how to limit the amount of digits of a function in Julia

Viewed 62

my function has to work with very big numbers, so in order to do that I used parts in my code such as big() . Unfortunately this resulted in giving me a result that is too precise (in other words its slowing the entire code down).

This is how the result looks like.

ΔE = 0.08298347005140644564908076516066986088852555871299296314640532293721884964540988

If possible I would like to limit the result to 4 digits

ΔE = 0.0829
1 Answers

If performance is a concern, probably the best way to do this is with https://github.com/dzhang314/MultiFloats.jl, e.g.

using MultiFloats
x = Float64x4(2.0)
# Calculations performed on x will have Float64x4 precision subsequently...

MultiFloats.jl appears to be the fastest package around at present for such calculations, and will let you choose from precision levels between Float64x2 and Float64x8. In any event, this will be dramatically faster than the BigFloats used in the example above.

Related