diff options
author | Simon Marlow <marlowsd@gmail.com> | 2008-05-12 10:38:47 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2008-05-12 10:38:47 +0000 |
commit | dcf739bd7fb7de140be3bafb4ce211e2e5c7bba9 (patch) | |
tree | 6f17822c4c2bfbf5b2d1dc51e0321383909a01f5 | |
parent | 89eac8928317774fdc3f283d78d3ff3cb315db5e (diff) | |
download | haskell-dcf739bd7fb7de140be3bafb4ce211e2e5c7bba9.tar.gz |
FIX #1861: floating-point constants for infinity and NaN in via-C
-rw-r--r-- | compiler/cmm/PprC.hs | 11 | ||||
-rw-r--r-- | includes/Stg.h | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs index a943575d51..9a3a3a2cf1 100644 --- a/compiler/cmm/PprC.hs +++ b/compiler/cmm/PprC.hs @@ -395,7 +395,16 @@ pprMachOpApp' mop args pprLit :: CmmLit -> SDoc pprLit lit = case lit of CmmInt i rep -> pprHexVal i rep - CmmFloat f rep -> parens (machRepCType rep) <> (rational f) + + CmmFloat f rep -> parens (machRepCType rep) <> str + where d = fromRational f :: Double + str | isInfinite d && d < 0 = ptext (sLit "-INFINITY") + | isInfinite d = ptext (sLit "INFINITY") + | isNaN d = ptext (sLit "NAN") + | otherwise = text (show d) + -- these constants come from <math.h> + -- see #1861 + CmmLabel clbl -> mkW_ <> pprCLabelAddr clbl CmmLabelOff clbl i -> mkW_ <> pprCLabelAddr clbl <> char '+' <> int i CmmLabelDiffOff clbl1 clbl2 i diff --git a/includes/Stg.h b/includes/Stg.h index 7f37783f4a..35f4eda631 100644 --- a/includes/Stg.h +++ b/includes/Stg.h @@ -31,6 +31,9 @@ */ #ifndef IN_STG_CODE # define IN_STG_CODE 1 +# define _ISOC99_SOURCE +// Turn on C99 for .hc code. This gives us the INFINITY and NAN +// constants from math.h, which we occasionally need to use in .hc (#1861) #endif #if IN_STG_CODE == 0 |