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

Fix fromRational bug #338

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,14 @@ testFromRational = databasePropertyTest "fromRational" \transaction -> do
pure $ fromRational rational
diff result (~=) double
where
a ~= b = abs (a - b) < 1e-15
wholeDigits x = fromIntegral $ length $ show $ round x
-- A Double gives us between 15-17 decimal digits of precision.
-- It's tempting to say that two numbers are equal if they differ by less than 1e15.
-- But this doesn't hold.
-- The precision is split between the whole numer part and the decimal part of the number.
-- For instance, a number between 10 and 99 only has around 13 digits of precision in its decimal part.
-- Postgres and Haskell show differing amounts of digits in these cases,
a ~= b = abs (a - b) < 10**(-15 + wholeDigits a)
infix 4 ~=


Expand Down
Loading