valderman / haste-compiler

A GHC-based Haskell to JavaScript compiler
http://haste-lang.org
BSD 3-Clause "New" or "Revised" License
1.44k stars 111 forks source link

Wrong results in floating point algorithms #62

Closed nomeata closed 11 years ago

nomeata commented 11 years ago

The library circle-packing compiles with haste. But it yiels wrong results in haste. Take this test case (test.hs):

{-# LANGUAGE CPP #-}
module Main where
import Optimisation.CirclePacking

#ifdef __HASTE__
import Haste
#endif

main = do
  let packed = packCircles id [4,4,4]
#ifdef __HASTE__
  writeLog $ show packed
#else
  putStrLn $ show packed
#endif

I get

$ runhaskell test.hs 
[(4.0,(0.0,4.618802153517006)),(4.0,(4.0,-2.309401076758503)),4.0,(-4.0,-2.309401076758503))]

but clearly wrong results with haste:

$ hastec test.hs --start=asap && nodejs test.js
Compiling Main into .
Compiling Optimisation.CirclePacking into .
Linking test.js
Linking Main
Linking GHC.Tuple
Linking GHC.Show
Linking GHC.Types
Linking GHC.List
Linking GHC.Base
Linking GHC.Float
Linking GHC.HastePrim
Linking Optimisation.CirclePacking
Linking GHC.Integer.Type
Linking Data.List
Linking GHC.Num
Linking Data.Tuple
[(4.0,(-168.0,170.5833129783411)),(4.0,(88.0,-85.29165648917053)),(4.0,(80.0,-85.29165648917053))]
nomeata commented 11 years ago

Interesting that the wrong numbers still have the right proportions, i.e. they are off by the same factor of 36.932370625238775.

nomeata commented 11 years ago

Thanks for the quick fix.