diff --git a/std/math.d b/std/math.d index 0ce6f21e114..1245abbafb2 100644 --- a/std/math.d +++ b/std/math.d @@ -768,10 +768,9 @@ real tan(real x) @trusted pure nothrow @nogc jc trigerr ; // x is NAN, infinity, or empty // 387's can handle subnormals SC18: fptan ; - fstp ST(0) ; // dump X, which is always 1 fstsw AX ; sahf ; - jnp Lret ; // C2 = 1 (x is out of range) + jnp Clear1 ; // C2 = 1 (x is out of range) // Do argument reduction to bring x into range fldpi ; @@ -789,6 +788,10 @@ trigerr: } return real.nan; +Clear1: asm pure nothrow @nogc{ + fstp ST(0) ; // dump X, which is always 1 + } + Lret: {} } else version(D_InlineAsm_X86_64) @@ -815,10 +818,9 @@ Lret: {} jnz trigerr ; // x is NAN, infinity, or empty // 387's can handle subnormals SC18: fptan ; - fstp ST(0) ; // dump X, which is always 1 fstsw AX ; test AH,4 ; - jz Lret ; // C2 = 1 (x is out of range) + jz Clear1 ; // C2 = 1 (x is out of range) // Do argument reduction to bring x into range fldpi ; @@ -837,6 +839,10 @@ trigerr: } return real.nan; +Clear1: asm pure nothrow @nogc{ + fstp ST(0) ; // dump X, which is always 1 + } + Lret: {} } else @@ -7174,6 +7180,12 @@ deprecated("Phobos1 math functions are deprecated, use isInfinity ") alias isinf real r = tan(-2.0L); assert(fabs(r - 2.18504f) < .00001); + + // Verify correct behavior for large inputs + assert(!isNaN(tan(0x1p63))); + assert(!isNaN(tan(0x1p300L))); + assert(!isNaN(tan(-0x1p63))); + assert(!isNaN(tan(-0x1p300L))); } @safe pure nothrow unittest