This is a session of my REPL
julia> setrounding(BigFloat, RoundDown)
MPFRRoundDown::MPFRRoundingMode = 3
julia> function f()
println(big"0.3")
end
f (generic function with 1 method)
julia> setrounding(BigFloat, RoundUp)
MPFRRoundUp::MPFRRoundingMode = 2
julia> f()
0.2999999999999999999999999999999999999999999999999999999999999999999999999999974
julia> function g()
println(big"0.3")
end
g (generic function with 1 method)
julia> g()
0.3000000000000000000000000000000000000000000000000000000000000000000000000000017
Here I make the following conclusion: what determines the rounding behaviour of a function is the rounding mode that was in play at the time the function was created. Changing the rounding mode at a later time doesn’t change the function’s behavior.
Here is another session of the REPL:
julia> setrounding(BigFloat, RoundUp)
MPFRRoundUp::MPFRRoundingMode = 2
julia> function h()
setrounding(BigFloat, RoundDown)
if true
println(big"0.3")
end
end
h (generic function with 1 method)
julia> h()
0.3000000000000000000000000000000000000000000000000000000000000000000000000000017
Here I make the following conclusion: what determined the rounding behavior inside the if’s body was the “global setrounding”, and not the “setrounding” inside h’s body.
Because I am new to Julia, I don’t understand this behavior so well. I need some help to understand the behavior I am noticing here.