Bug 356 – std,math.tan doesn't preserve NaN payloads [fix included]
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-09-20T07:27:00Z
Last change time
2014-02-15T13:29:06Z
Keywords
patch
Assigned to
bugzilla
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2006-09-20T07:27:13Z
Currently in tan(x), it effectively does
if (isnan(x)) return real.nan;
when it should be
if (isnan(x)) return x;
The good news is that all math functions preserve NaN payloads, with this one exception. And it's a one-line fix.
In the asm code for tan, at the end of the code, add the line "jnp Lret".
-------
trigerr:
jnp Lret ; // if x is NaN, return x. <<< ADD THIS LINE
fstp ST(0) ; // dump x, which will be infinity
}
return real.nan;
Lret:
;
}
---------
Also, tan() currently fails one if its unit tests ( tan(1e100)). Since the isnan(tan(1e100)) is not correct mathematically, I think that line should just be removed.
--------
// overflow
[ real.infinity, real.nan],
[ real.nan, real.nan],
[ 1e+100, real.nan], <<< REMOVE THIS LINE
];
--------
Comment #1 by aldacron — 2006-09-25T13:45:25Z
[email protected] wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=356
>
> Summary: std,math.tan doesn't preserve NaN payloads [fix
> included]
> Product: D
> Version: 0.167
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Severity: minor
> Priority: P1
> Component: Phobos
> AssignedTo: [email protected]
> ReportedBy: [email protected]
>
>
> Currently in tan(x), it effectively does
> if (isnan(x)) return real.nan;
> when it should be
> if (isnan(x)) return x;
>
> The good news is that all math functions preserve NaN payloads, with this one
> exception. And it's a one-line fix.
I spoke too soon. The version(linux) form of pow() should have two lines
changed:
if (isnan(y))
return y; // <<< instead of "return real.nan" <<<<<<<<
if (y == 0)
return 1; // even if x is $(NAN)
if (isnan(x) && y != 0)
return x; // instead of "return real.nan;" <<<<<<