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 conversion from floats #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

barucden
Copy link
Collaborator

@barucden barucden commented Nov 6, 2024

Numbers such as 0.3 or 1.1 cannot be represented exactly using Float32 or Float64. We can all digits by converting them to BigFloat:

julia> big(0.3)
0.299999999999999988897769753748434595763683319091796875

julia> big(1.1)
1.100000000000000088817841970012523233890533447265625

This PR updates the Decimal constructors so that floating point numbers are converted to Decimals exactly in the sense that

julia> hash(1.1) == hash(Decimal(1.1))
true

Fixes #85

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.69%. Comparing base (514bf8a) to head (4d37211).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #86   +/-   ##
=======================================
  Coverage   99.68%   99.69%           
=======================================
  Files          11       11           
  Lines         319      329   +10     
=======================================
+ Hits          318      328   +10     
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Numbers such as `0.3` or `1.1` cannot be represented exactly using
`Float32` or `Float64`. We can all digits by converting them to
`BigFloat`:
```julia
julia> big(0.3)
0.299999999999999988897769753748434595763683319091796875

julia> big(1.1)
1.100000000000000088817841970012523233890533447265625
```
This PR updates the `Decimal` constructors so that floating point
numbers are converted to `Decimal`s exactly in the sense that
```julia
julia> hash(1.1) == hash(Decimal(1.1))
true
```

Fixes JuliaMath#85
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

Successfully merging this pull request may close these issues.

Inexact construction of Decimal from float
1 participant