4
$\begingroup$

What happens at the end of MachinePrecision? Is the remainder discarded or rounded?

This code suggests it is discarded; is that conclusion correct? Why is it not rounded?

BaseForm[InputForm[1 + $MachineEpsilon], 2]
BaseForm[InputForm[1 + 1/2*$MachineEpsilon + 1/4*$MachineEpsilon], 2]
$\endgroup$
  • $\begingroup$ @nikie But this seems to be rounded: BaseForm[InputForm[1 + 0.1], 2] $\endgroup$ – GambitSquared Dec 5 '16 at 9:33
  • $\begingroup$ Well, that's my question, whether the remainder is discarded or rounded (possibly up) $\endgroup$ – GambitSquared Dec 5 '16 at 9:37
7
$\begingroup$

It looks like it's rounded to nearest, with ties to 0, but since this rounding is done by the CPU, it might even be system dependent. On my system I get:

BaseForm[InputForm[1.0 + $MachineEpsilon*0.5], 2]

2^^1.

BaseForm[InputForm[1.0 + $MachineEpsilon*0.500000001], 2]

2^^1.0000000000000000000000000000000000000000000000000001

Note also that floating point addition is not associative, so this:

BaseForm[InputForm[(1 + 1/2*$MachineEpsilon) + 1/4*$MachineEpsilon],
  2]

2^^1.

is not the same as this:

BaseForm[InputForm[1 + (1/2*$MachineEpsilon + 1/4*$MachineEpsilon)],
  2]

2^^1.0000000000000000000000000000000000000000000000000001

| improve this answer | |
$\endgroup$
  • 3
    $\begingroup$ I think the rules are set firmly by IEEE 754. $\endgroup$ – The Vee Dec 5 '16 at 15:01
  • $\begingroup$ I'm seeing rounding to nearest with round ties to even, which is in accordance with one of the options in IEEE 754 (2008). My experience on this site is that numerics have been consistent with the results on my machine so that it is unlikely that different systems use different rounding attributes. @TheVee: An implementation of IEE 754 is supposed to support all rounding attributes, including the three other directed rounding attributes, but in practice, it seems systems do not always provide a way for users to select the mode. $\endgroup$ – Michael E2 Dec 5 '16 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.