Skip to content
New issue

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

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

Already on GitHub? # to your account

Rounded option in the normalize function #36

Closed
hurak opened this issue Sep 10, 2019 · 0 comments · Fixed by #88
Closed

Rounded option in the normalize function #36

hurak opened this issue Sep 10, 2019 · 0 comments · Fixed by #88

Comments

@hurak
Copy link
Contributor

hurak commented Sep 10, 2019

I am checking the code for the normalize function at https://github.com/JuliaMath/Decimals.jl/blob/master/src/norm.jl and I suspect there are two problems in how the rounded option is handled.

First, the code on line 12 is run if rounded is set to true. But clearly this line computes the output without rounding. It is only the else branch that does something containing rouding. I suspect the logic here is inverted.

Second, on line 14, where rounding is performed, the digits parameter is set to DIGITS. But it is unclear to me where this DIGITS comes from - it is not entered while calling the normalize function. Is it intended to be a global variable? EDIT: I see, it is a const set in the module to 20. It does not work anyway as I would anticipate. The code below:

julia> h = Decimal(0,2540,-4)
Decimal(0, 2540, -4)

julia> f = normalize(h)
Decimal(0, 254, -3)

julia> f = normalize(h,rounded=false)
Decimal(0, 254, -3)

julia> f = normalize(h,rounded=true)
Decimal(0, 254, -3)

julia> DIGITS=1
1

julia> f = normalize(h,rounded=true)
Decimal(0, 254, -3)

For comparision with a standard float:

julia> round(0.254,digits=1)
0.3

I am running this in REPL.

@barucden barucden mentioned this issue Oct 26, 2024
barucden added a commit to barucden/Decimals.jl that referenced this issue Nov 6, 2024
The PR replaces `round` and `normalize`.

Fixes JuliaMath#27
Fixes JuliaMath#36
Fixes JuliaMath#39
Fixes JuliaMath#50
barucden added a commit to barucden/Decimals.jl that referenced this issue Nov 7, 2024
The PR replaces `round` and `normalize`.

Fixes JuliaMath#27
Fixes JuliaMath#36
Fixes JuliaMath#39
Fixes JuliaMath#50
barucden added a commit to barucden/Decimals.jl that referenced this issue Nov 7, 2024
The PR replaces `round` and `normalize`.

Fixes JuliaMath#27
Fixes JuliaMath#36
Fixes JuliaMath#39
Fixes JuliaMath#50
barucden added a commit to barucden/Decimals.jl that referenced this issue Nov 7, 2024
The PR replaces `round` and `normalize`.

Fixes JuliaMath#27
Fixes JuliaMath#36
Fixes JuliaMath#39
Fixes JuliaMath#50
barucden added a commit to barucden/Decimals.jl that referenced this issue Nov 7, 2024
The PR replaces `round` and `normalize`.

Fixes JuliaMath#27
Fixes JuliaMath#36
Fixes JuliaMath#39
Fixes JuliaMath#50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant