Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Ratio Integer" (from Data.Ratio) uses 32 bit arithmetic instead of Integers #425

Open
sachera opened this issue Jun 13, 2019 · 0 comments

Comments

@sachera
Copy link

sachera commented Jun 13, 2019

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant