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

Rounded option in the normalize function #36

Open
hurak opened this issue Sep 10, 2019 · 0 comments
Open

Rounded option in the normalize function #36

hurak opened this issue Sep 10, 2019 · 0 comments

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.

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