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

InexactError for parsing/conversion #93

Closed
chbian opened this issue May 8, 2019 · 2 comments · Fixed by #94
Closed

InexactError for parsing/conversion #93

chbian opened this issue May 8, 2019 · 2 comments · Fixed by #94

Comments

@chbian
Copy link

chbian commented May 8, 2019

I am running Julia 0.7.0 on Linus/CentOS and get the following InexactError,

julia> parse(Dec64, "3935767060.093896713")
ERROR: InexactError: parse(Dec64, 3935767060.093896713)
Stacktrace:
 [1] parse(::Type{Dec64}, ::String) at /home/user/.julia/packages/DecFP/3jJW7/src/DecFP.jl:66
 [2] top-level scope at none:0

julia> parse(Float64, "3935767060.093896713")
3.935767060093897e9

Parsing the value to Float64 works fine. But it fails to parse to Dec64. Any idea why it happens? Thanks!

@chbian
Copy link
Author

chbian commented May 9, 2019

I guess I know the reason. IEEE 754 decimal 64 type may have 16 significant bits or decimal digits. The string I tried to parse in the previous example is too long for Dec64.

@chbian chbian closed this as completed May 9, 2019
@stevengj stevengj changed the title Help on InexactError InexactError for parsing/conversion May 9, 2019
@stevengj stevengj reopened this May 9, 2019
@stevengj
Copy link
Member

stevengj commented May 9, 2019

I'm going to re-open this, since it's not clear that we should be throwing an InexactError here, and also for conversion between decimal types:

julia> Dec64(d128"3935767060.093896713")
ERROR: InexactError: convert(Dec64, 3.935767060093896713e9)

We should probably emulate the Float64 behavior here and silently round when parsing/converting values that can't be represented exactly.

julia> Dec64(3935767060.093896713)
3.935767060093897e9

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 a pull request may close this issue.

2 participants