haste-compiler
haste-compiler copied to clipboard
"Ratio Integer" (from Data.Ratio) uses 32 bit arithmetic instead of Integers
Using Rational (equals Ratio Integer) in a haste program results in wrong values if the nominator exceeds 2^32-1. The denominator on the other hand seems to work as expected.
Minimal example:
import Data.Ratio
testInteger :: String -> String
testInteger a = show (read a :: Integer)
testRational :: String -> String
testRational a = show ((read a :: Integer) % 1)
testRational2 :: String -> String
testRational2 a = show (1 % (read a :: Integer))
main = do
putStrLn $ testInteger "1234567890"
putStrLn $ testInteger "12345678901"
putStrLn $ testRational "1234567890"
putStrLn $ testRational "12345678901"
putStrLn $ testRational2 "1234567890"
putStrLn $ testRational2 "12345678901"
Expected Output (console):
1234567890
12345678901
1234567890 % 1
12345678901 % 1
1 % 1234567890
1 % 12345678901
Actual Output (line 4 is different):
1234567890
12345678901
1234567890 % 1
3755744309 % 1
1 % 1234567890
1 % 12345678901
It is noteworthy that mod 12345678901 (2^32)
equals 3755744309
. Compiling with ghc and running the program on the console works as expected.
Used Versions:
hastec --version
0.6.0.0
ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3