It's not the number representation that's any different. Julia's Float64 corresponds to C double, Float32 corresponds to C float. What's different is the number of digits presented in the output by default. Julia uses the Grisu algorithm http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf to print the shortest number of decimal digits which round to the same binary floating-point number. Matlab and C printf generally pick a shorter number of default digits, depending on format options or printf specifiers.
On Thursday, September 3, 2015 at 11:57:38 PM UTC-7, Konstantinos Prokopidis wrote: > > hi, > > I perform some tests on julia precision as follows (on my 32-bit computer) > > julia> 0.1-0.3 > -0.19999999999999998 > > julia> 0.1f0-0.3f0 > -0.20000002f0 > > julia> 0.1e0-0.3e0 > -0.19999999999999998 > > julia> float32(0.1-0.3) > -0.2f0 > > julia> float64(0.1-0.3) > -0.19999999999999998 > > On the contrary in MATLAB and C (using either double of float) we get > -0.2 > > Why there are the above differences? Do we have different number > representation in the C language? > > Thanks a lot > >
