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

Constructor loses precision when parsing small numbers expressed in scientific notation ("e" format). #45

Open
StrangeRay opened this issue Jan 4, 2020 · 0 comments

Comments

@StrangeRay
Copy link

The problem is perhaps best explained by example. Consider the construction of the decimal 1.23456789×10⁻²¹ via decimal("1.23456789e-21"). The result should display as
Decimal(0, 123456789, -29) but I get Decimal(0, 0, -20) instead. Observe the progressive loss of significance in the following constructions:

julia> using Decimals

julia> decimal("1.23456789") # Ok
Decimal(0, 123456789, -8)

julia> decimal("1.23456789e-11") # Ok
Decimal(0, 123456789, -19)

julia> decimal("1.23456789e-12") # Still Ok
Decimal(0, 123456789, -20)

julia> decimal("1.23456789e-13") # Not quite
Decimal(0, 12345679, -20)

julia> decimal("1.23456789e-14") # Constructor loses one significant digit per decade
Decimal(0, 1234568, -20)

julia> decimal("1.23456789e-15") # Trend continues ...
Decimal(0, 123457, -20)

julia> # ...
       
       decimal("1.23456789e-18") # ...
Decimal(0, 123, -20)

julia> decimal("1.23456789e-19") # ...
Decimal(0, 12, -20)

julia> decimal("1.23456789e-20") # Down to one significant digit
Decimal(0, 1, -20)

julia> decimal("1.23456789e-21") # All significant digits are lost
Decimal(0, 0, -20)

The problem is traceable to the implementation of function scinote. In particular, see line 39 in file decimal.jl.

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