I’m just getting started with Julia and I ran across something that confused me in this section of the docs; Promotion. It shows the following example:
julia> promote(1, 2.5, 3, 3//4) (1.0, 2.5, 3.0, 0.75)
I was surprised that the Rational was promoted to a Float. It seems like you can lose accuracy with that conversion. I tried the following and I think this confirms my suspicion:
julia> a,b = promote(0.25, 1//10) (0.25, 0.1) julia> @printf("%.55f\n%.55f", a, b) 0.2500000000000000000000000000000000000000000000000000000 0.1000000000000000055511151231257827021181583404541015625 julia> convert(Rational, b) 3602879701896397//36028797018963968
The Float is not exactly 1/10 and the value doesn’t round-trip back to 1/10.
I’m wondering, is there an explanation or discussion about this that I can read? If I wanted to reverse this behavior (convert the Float to a Rational in this case), is that something I can override?
Thanks for any help and insight into this!