You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The logic for multipleOf compares the remainder of a division with the f64 EPSILON constant to decide if a number is a multiple or not. This approach doesn't make sense. EPSILON is simply the difference between 1.0 and the next larger representable number. With regards to the multipleOf calculation this is just an arbitrary constant and comparing remainders to it gives us no guarantees.
EG:
1e-15 is a multiple of 1e-16. But (1e-15 / 1e-16) % 1.0 = 1.7763568394002505e-15 which is greater than epsilon so it is incorrectly said to not be a multiple.
1.3e-16 is not a multiple of 1.3. But (1.3e-16 / 1.3) % 1.0 = 9.999999999999999e-17 which is less than epsilon so it is incorrectly said to be a multiple.
The text was updated successfully, but these errors were encountered:
At a high level this solution works by multiplying both values by the smallest power of 10 that makes them both whole numbers and does the division on whole numbers to sidestep the issues with floating point math on fractions.
The logic for multipleOf compares the remainder of a division with the f64 EPSILON constant to decide if a number is a multiple or not. This approach doesn't make sense. EPSILON is simply the difference between 1.0 and the next larger representable number. With regards to the multipleOf calculation this is just an arbitrary constant and comparing remainders to it gives us no guarantees.
EG:
1e-15 is a multiple of 1e-16. But
(1e-15 / 1e-16) % 1.0 = 1.7763568394002505e-15
which is greater than epsilon so it is incorrectly said to not be a multiple.1.3e-16 is not a multiple of 1.3. But
(1.3e-16 / 1.3) % 1.0 = 9.999999999999999e-17
which is less than epsilon so it is incorrectly said to be a multiple.The text was updated successfully, but these errors were encountered: