precision in julia

185 Views Asked by At

I am having trouble working with high precision in julia. I am not able to set a precision of 240 decimal places. I am currently using the BigFloat package, it is the most suitable for me at the moment.

I have this code:

epsilon = big(10)^(-240)

a = BigFloat("1.0") + epsilon

println(a)

This is my epsilon: 1.000000000000000000000000000000000000000000000000000000000000000000000000000522e-240there is a small error, "522", but we will disregard it for now. the problem is that I get a = 1.0. I would like it to be a = 1+10^-240

obs. I need to perform several calculations with a high precision, of 250 decimal places, but I am having problems defining this high precision in julia.

1

There are 1 best solutions below

2
Bogumił Kamiński On BEST ANSWER

Use the setprecision function with base=10:

julia> setprecision(BigFloat, 250; base=10)
250

julia> epsilon = big(10)^(-240)
9.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999991631e-241

julia> a = BigFloat("1.0") + epsilon
1.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000005