Talk:Approximate equality: Difference between revisions

m
 
(5 intermediate revisions by the same user not shown)
Line 1:
==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 saysimplies "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).
 
I would like to change this test case to involve numbers a few binary orders of magnitude less (to give room for languages with slightly smaller floats) and perhaps also include a test-case for 32-bit and/or 16-bit floats, in order to force implementations in any language to allow for differences in magnitude, but the fact that this would invalidate many existing solutions may be an issue. Perhaps the existing solutions which operate only on an absolute difference between numbers could be moved to a different page? [[User:Goose121|Goose121]] ([[User talk:Goose121|talk]]) 00:04, 20 November 2021 (UTC)
 
:I made a minor grammatical adjustment to your post which made it clearer to me, says x ==> implies "x".
:It (now) strikes me the third case should really have had two 1 on the rhs, then it would be a blatent error if test 1 and test 3 gave different results.
:<small>(Clearly the Java/Lua entries should be given some sort of special prize for getting cases 3, 4, 6, ''and'' 7 wrong!)</small>
:The tests should have expected results explicitly stated, that is beyond 1 and 2, "Otherwise answers may vary and still be correct." is an absolute cop-out if ever I saw one.
:A consistent output should be specified (maybe like R), I quite like the idea of "==" and "~=" columns. I could go on.
:You should write a list here of any further tests you'd like to see.
:Remember all this is really much more "compare languages" as opposed to "write a useful function", I guess.
:Marking existing answers as needing review is not unprecedented, but needs 4 or 5 "ayes" here --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 13:51, 20 November 2021 (UTC)
 
==Can of worms==
7,794

edits