[Yhc] Possible bug with floats

Dimitry Golubovsky golubovsky at gmail.com
Thu Oct 26 22:25:24 EDT 2006


Neil,

I have added missing show functions for CoreFloat and CoreDouble.
While testing, I came across this issue:

Haskell:

module Vt1 where

...

y :: Float -> Float

y f = case f of
  1.0 -> 2.0
  3.45 -> 0.2e-4
  0.99 -> 7.463
  other -> -3.65

Core:

Vt1.y v423 =
    case (YHC.Internal._eqFloat v423 1.0) of
        Prelude.True -> 2.0
        Prelude.False -> -3.65

It looks like a case expression was converted as an if expression.

Hopefully this is only a Core problem because:
bash$ cat fltest.hs
module Main where

y :: Float -> Float

y f = case f of
  1.0 -> 2.0
  3.45 -> 0.2e-4
  0.99 -> 7.463
  other -> -3.65

main = do
  putStrLn $ show (y 1.0)
  putStrLn $ show (y 3.45)
  putStrLn $ show (y 0.99)
  putStrLn $ show (y 4.56)

bash$ yhc fltest.hs
Compiling Main             ( fltest.hs )

bash$ yhi Main.hbc
2.0
2.0e-5
7.463
-3.65

i. e. the program works OK.



-- 
Dimitry Golubovsky

Anywhere on the Web


More information about the Yhc mailing list