Reputation: 83
I'm learning about machine epsilon in single and double precision and comparing values from different programs. For example, in matlab the following code:
>> format long
>> eps
gives 2.220446049250313e-16. But the following code in Maple:
> readlib(Maple_floats);
> evalhf(DBL_EPSILON);
> quit;
gives -15 .2220446049250314 10 (where -15 is exponent).
There is a slight difference in output between the two programs. Maple appears to round up from 3 to 4. What is the reason for this difference?
Upvotes: 2
Views: 705
Reputation: 7271
Note that Maple (and Matlab) are showing you a radix-10 representation of a hardware double precision floating point number.
So perhaps you should be more concerned with the underlying hardware double precision value.
> restart:
> kernelopts(version);
Maple 2015.0, X86 64 LINUX, Feb 17 2015, Build ID 1022128
> X:=Vector(1,datatype=float[8]): # double precision container
> p:=proc(x) x[1]:=DBL_EPSILON; end proc:
> evalhf(p(X)):
> lprint(X[1]);
HFloat(.222044604925031308e-15)
> printf("%Y\n", X[1]);
3CB0000000000000
That last result is "formatted in byte-order-independent IEEE hex dump format (16 characters wide)", according to the documentation.
So, what does Matlab give you when you printf
its eps
in the equivalent format? A quick web-search seems to reveal that it'll give 3CB0000000000000 alongside that 2.220446049250313e-16 you saw.
In other words: the hardware double precision representation is the same in both systems. They are representing it differently in base 10. Note that the base 10 value displayed by Maple has 18 decimal places. The digits past the 15th are artefacts of a sort, stored so that in general internally stored numbers can round-trip correctly for repeated conversion both ways. Note that hardware double precision relates to something between 15 and 16 decimal places. So if you want to compare between the two systems you could (and likely should) compare the stored hardware double precision values and not the base 10 representations past the 15th place.
Upvotes: 7