Skip to content

Commit 6e503ec

Browse files
committed
Fix #22489 - e - e is not 0 with NaNs
1 parent 28f246f commit 6e503ec

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

compiler/src/dmd/backend/cgelem.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ private elem* elmin(elem* e, Goal goal)
12261226
}
12271227

12281228
// Replace (e - e) with (0)
1229-
if (el_match(e1,e2) && !el_sideeffect(e1))
1229+
if (el_match(e1,e2) && !el_sideeffect(e1) && !tyfloating(tym))
12301230
{
12311231
el_free(e);
12321232
e = el_calloc();

compiler/test/runnable/test22489.d

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
REQUIRED_ARGS: -inline -O
3+
RUN_OUTPUT:
4+
---
5+
32767
6+
32767
7+
---
8+
*/
9+
10+
enum ushort EXPMASK = 0x7FFF;
11+
12+
version (LittleEndian)
13+
enum EXPPOS_SHORT = 4;
14+
else
15+
enum EXPPOS_SHORT = 0;
16+
17+
int getExp(real x, real y)
18+
{
19+
real diff = x - y;
20+
ushort* pa = cast(ushort*)(&x);
21+
ushort* pb = cast(ushort*)(&y);
22+
ushort* pd = cast(ushort*)(&diff);
23+
return pd[EXPPOS_SHORT] & EXPMASK;
24+
}
25+
26+
void main()
27+
{
28+
import core.stdc.stdio;
29+
printf("%d\n", getExp(real.nan, real.nan));
30+
printf("%d\n", getExp(real.nan, real.nan));
31+
}

0 commit comments

Comments
 (0)