FIX #1861: floating-point constants for infinity and NaN in via-C
[ghc-hetmet.git] / compiler / cmm / PprC.hs
index a943575..9a3a3a2 100644 (file)
@@ -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