-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: use standard checks for float comparisons
- Loading branch information
1 parent
42e314d
commit cf9498e
Showing
7 changed files
with
164 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
cf9498e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UweKrueger what is the motivation behing making
==
operator for floats behave like bitwise (i.e. unrelated to floats/doubles) equality check?There was an agreement (see #2133 and #2158 ), that comparing floats with epsilon (at best dynamically - see e.g. g-truc/glm@72327ce ) is nowadays a standard practise (Lua, JS, ...) and only older languages like (C being one of them) have the flaw. It's a notorious source of bugs. In V it's also problematic to make
==
compare bitwise because of JS backend. Last it's super easy and maximally performant to use intrinsicbiteq()
method.Could you maybe shed some light on this significant and backwards-incompatible change?
@spytheman @medvednikov thoughts?
cf9498e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dumblob please have a look at issue/discussion #5180 and the comments to PR #5203.
cf9498e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dumblob BTW: Are you sure about lua? I've just checked the source code of lua-5.3.5 and lua-5.4.0rc4: in both versions
float
comparisons are done withluai_numeq()
which is a macro that expands just to the standard C comparison:#define luai_numeq(a,b) ((a)==(b))
. I've also checked the interpreter and have not found any hints for an implied tolerance in float comparisons.cf9498e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dumblob Javascript seems to do a standard IEEE754 comparison, too, IMHO...
Python also uses standard comparisons. In numpy there is an interesting function (which is of cause not used for default comparisons):
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
which allows sophisticated checks with relative and absolute tolerance.