From the documentation for real
Note: In QML all reals are stored in double precision, IEEE floating point format.
From the documentation on data type conversion
+----------------+----------------+
| Qt Type | QML Basic Type |
+----------------+----------------+
| [...] | [...] |
| double | double |
| [...] | [...] |
| float, qreal | real |
+----------------+----------------+
So, according to the documentation not everything is neccessarily casted to real
, but everything will have the same precision, so I think you can cast or compare them as you like.
You can either create a JavaScript Library in which you implement the function, just as described in your question.
Or you can create a C++-Object, and expose a this function, so you have the implementation directly in C++. Then you can decide, whether you instantiate this object in every file, where you need it, or if you create a singleton instance as library. AFAIK QML has problems with static functions and needs an instance of the object.
I don't know of any predefined variable in QML that specifies an epsilon
. In C++, for me it is:
std::numeric_limits<double>::epsilon() -> 2.220446049250313e-16
so something around this might be a good choice.