From: sof Date: Thu, 29 Jan 1998 13:48:00 +0000 (+0000) Subject: [project @ 1998-01-29 13:48:00 by sof] X-Git-Tag: Approx_2487_patches~1036 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=d67e82cf98b82ee5028738a2644ce6a1c47d2aa7;p=ghc-hetmet.git [project @ 1998-01-29 13:48:00 by sof] Don't use typecasts to convert floats to ints, use unions. --- diff --git a/ghc/lib/cbits/floatExtreme.lc b/ghc/lib/cbits/floatExtreme.lc index 894ff7a..3dbecde 100644 --- a/ghc/lib/cbits/floatExtreme.lc +++ b/ghc/lib/cbits/floatExtreme.lc @@ -6,6 +6,11 @@ Stubs to check for extremities of (IEEE) floats, the tests have been (artfully) lifted from the hbc-0.9999.3 (lib/fltcode.c) source. +ToDo: + - avoid hard-wiring the fact that on an + Alpha we repr. a StgFloat as a double. + (introduce int equivalent of {ASSIGN,PK}_FLT? ) + \begin{code} #include "rtsdefs.h" @@ -80,49 +85,75 @@ StgDouble d; return (u.i[H] == 0x80000000 && u.i[L] == 0); } +/* Same tests, this time for StgFloats. */ + StgInt isFloatNaN(f) StgFloat f; { - int ix; +#if !defined(alpha_TARGET_OS) + /* StgFloat = double on alphas */ + return (isDoubleNaN(f)); +#else + union { StgFloat f; int i; } u; int r; + u.f = f; - ix = (int)f; - ix &= 0x7fffffff; - ix = 0x7f800000 - ix; - r = (int)(((unsigned int)(ix))>>31); + u.i &= 0x7fffffff; + u.i = 0x7f800000 - u.i; + r = (int)(((unsigned int)(u.i))>>31); return (r); +#endif } StgInt isFloatInfinite(f) StgFloat f; { +#if !defined(alpha_TARGET_OS) + /* StgFloat = double on alphas */ + return (isDoubleInfinite(f)); +#else int ix; + union { StgFloat f; int i; } u; + u.f = f; - ix = (int)f; - ix &= 0x7fffffff; - ix ^= 0x7f800000; - return (ix == 0); + u.i &= 0x7fffffff; + u.i ^= 0x7f800000; + return (u.i == 0); +#endif } StgInt isFloatDenormalized(f) StgFloat f; { - int high, iexp; +#if !defined(alpha_TARGET_OS) + /* StgFloat = double on alphas */ + return (isDoubleDenormalized(f)); +#else + int iexp; + union { StgFloat f; int i; } u; + u.f = f; - high = (int)f; - iexp = high & (0xff << 23); + iexp = u.i & (0xff << 23); return (iexp == 0); +#endif } StgInt isFloatNegativeZero(f) StgFloat f; { - int high = (int)f; - return (high == 0x80000000); +#if !defined(alpha_TARGET_OS) + /* StgFloat = double on alphas */ + return (isDoubleNegativeZero(f)); +#else + union { StgFloat f; int i; } u; + u.f = f; + + return (u.i == (int)0x80000000); +#endif }