Talk:Approximate equality: Difference between revisions

Content added Content deleted
(Insufficient test cases)
Line 1: Line 1:
==Insufficient test cases and incorrect implementations==
==Insufficient test cases and incorrect implementations==
The test cases for this problem are insufficient to ensure that the solutions handle numbers differently at different scales in many common languages, even though the problem description says that they should. Specifically, using a 64-bit IEEE floating point number (which is the largest many languages offer, and some only offer even smaller floating point types), the test-case numbers 100000000000000.01 and 100000000000000.011, which the problem statement says should test whether larger numbers are allowed larger errors, are actually equal, with the representation 100000000000000.015625. At present, this oversight is exploited by many (if not most) of the implementations, which simply test whether the absolute difference of the inputs is less than 1e-18.
The test cases for this problem are insufficient to ensure that the solutions handle numbers differently at different scales in many common languages, even though the problem description says that they should. Specifically, using a 64-bit IEEE floating point number (which is the largest many languages offer, and some only offer even smaller floating point types), the test-case numbers 100000000000000.01 and 100000000000000.011, which the problem statement says should test whether larger numbers are allowed larger errors, are actually equal, with the representation 100000000000000.015625. At present, this oversight is exploited by many (if not most) of the implementations, which simply test whether the absolute difference of the inputs is less than 1e-18. As the test cases stand, it would technically be correct to simply test if a == b.


Specifically, the incorrect solutions are any which are based (directly or indirectly) on the C# solution, the Delphi solution (as its standard comparison function only uses an absolute difference), the FreeBasic solution, the Mathematica solution, the Scala solution, and the Wren solution. It seems that especially many of the more popular languages have incorrect solutions (as many are based on the C#, C, or Java solution).
Specifically, the incorrect solutions are any which are based (directly or indirectly) on the C# solution, the Delphi solution (as its standard comparison function only uses an absolute difference), the FreeBasic solution, the Mathematica solution, the Scala solution, and the Wren solution. It seems that especially many of the more popular languages have incorrect solutions (as many are based on the C#, C, or Java solution).