JuliaMath/Decimals.jl

Unable to get more the 17 digits acuracy.

aaljuffali opened this issue · 2 comments

Thank for this small but handy Decimals library. I wanted to increase the 8 digits to 20 and it went crazy on me. It spit random numbers. It worked up to 17 digits. I did this by changing the DIGITS variable in Decimals.jl

I looked at the round.jl source code and I did some modification so that variables and numbers are explicitly converted to the same type. It worked.

This is the testing code:

using Decimals

function tet()
b = 1.0000001
a = decimal("1.0000001")
for i in(1:27)
a = a_a
b = b_b
end
println(a)
println(b)
end

tet()

This is the modified round.jl:

Rounding

function Base.round(x::Decimal, dpts::Int=0; normal::Bool=false)
shift = BigInt(dpts) + x.q
if shift > BigInt(0) || shift < x.q
(normal) ? x : norm(x, rounded=true)
else
c = Base.round(x.c / BigInt(10)^(-shift))
d = Decimal(x.s, BigInt(c), x.q - shift)
(normal) ? d : norm(d, rounded=true)
end
end

Make sure you set DIGITS = 20 before testing.

Sorry it's taken me a while to get back to you on this. Yes, I just tested your example, and it really does go crazy! Implemented your fixed version of round in 5a37637.

Thanks a bunch for your help :)

You Welcome.

On Jul 6, 2015, at 07:14, Jack Peterson notifications@github.com wrote:

Closed #10 #10.


Reply to this email directly or view it on GitHub #10 (comment).