-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make std.math.isIdentical work in CTFE #7515
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request, @n8sh! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#7515" |
In general, it seems the only reason for that function is that DMD includes the padding bytes for bool isIdentical(real a, real b) {
return a is b;
}
static assert(isIdentical(2, 0x1p1));
static assert(!isIdentical(0.0L, -0.0L)); The comment is misleading as well, as equal but different representations (think 0x2p0, 0x1p1) aren't (bitwise) identical, so it's not just about sign for zero and NaN payloads. Edit: GDC apparently also just compares the 10 bytes: https://godbolt.org/z/3z3W36 |
I'd give another reason: |
If you look at the asm, LDC and GDC definitely don't - they use memcmp. |
Really? Because |
Yes, really, as easily shown in IR or ASM output. When looking at the AST output, you'll see that the frontend 'optimizes' your assert to an |
The culprit almost certainly being https://github.com/dlang/dmd/blob/2efa5242753e75f88c2f559c5be8adb4584d5e5c/src/dmd/expression.d#L566-L569. |
std/math.d
Outdated
if (__ctfe) | ||
{ | ||
if (x !is y) return false; | ||
if (x == x) return true; |
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.
Shouldn't that be x == y
?
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.
Yes
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.
Ah, now I remember. It doesn't matter: the only circumstance where x is y
but not x == y
is if both x and y are NaN. So checking x == x
is the same as checking x == y
(it's a NaN check).
so this whole function could in principle be rewritten as |
Sending this to @thewilsonator to see if he can Salvage it. |
If the above is not true this should not be approved.