I'm new to js, and thus far have not seen the epsilon defined in any other languages. I recall in school calculating machine epsilon as an exercise. The only other time I've dealt with comparing floats we had to define our own acceptable epsilon. Is this very handy definition something that any other languages have implemented?
Defining your own epsilon - as you have done before - is the correct thing to do.
The "double epsilon" defined in various languages and frameworks is not an intended as some "margin of error" for performing comparisons - it's just the smallest possible increment you could ever represent with the number type.
Because we are talking about floating point numbers (not fixed scale/precision numbers), the level of precision specified by Number.Epsilon is only possible when you are storing a very small number - otherwise the precision will change depending on the number you store.
See my wordy reply to the original article ( dev.to/alldanielscott/comment/b46f ) for why the code recommended in the article here is not safe!
They sure do. C defines the values of ε for float, double, and long double floating point types in the standard header float.h as the constants FLT_EPSILON, DBL_EPSILON, and LDBL_EPSILON.
I'm new to js, and thus far have not seen the epsilon defined in any other languages. I recall in school calculating machine epsilon as an exercise. The only other time I've dealt with comparing floats we had to define our own acceptable epsilon. Is this very handy definition something that any other languages have implemented?
Defining your own epsilon - as you have done before - is the correct thing to do.
The "double epsilon" defined in various languages and frameworks is not an intended as some "margin of error" for performing comparisons - it's just the smallest possible increment you could ever represent with the number type.
Because we are talking about floating point numbers (not fixed scale/precision numbers), the level of precision specified by Number.Epsilon is only possible when you are storing a very small number - otherwise the precision will change depending on the number you store.
See my wordy reply to the original article ( dev.to/alldanielscott/comment/b46f ) for why the code recommended in the article here is not safe!
They sure do. C defines the values of ε for float, double, and long double floating point types in the standard header
float.has the constantsFLT_EPSILON,DBL_EPSILON, andLDBL_EPSILON.Awesome, thanks!