Re: bug in IntegerPart ?
- To: mathgroup at smc.vnet.net
- Subject: [mg47813] Re: bug in IntegerPart ?
- From: Jon Harrop <jdh30 at cam.ac.uk>
- Date: Tue, 27 Apr 2004 04:48:07 -0400 (EDT)
- Organization: University of Cambridge
- References: <c6g015$4lk$1@smc.vnet.net> <c6ibta$6i2$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
AC wrote:
> Your 'explanation' makes no sense whatsoever. Mathematica's binary
> representations of 1.65-1.3 and 0.35 are the same.
No, they are not.
> That can be seen by
> comparing
> BaseForm[1.65 - 1.3, 2]
> with
> BaseForm[0.35,2]
BaseForm[...] gives you fewer digits than RealDigit[...], so it isn't giving
you enough of them...
> The problem occurs because Mathematica changes, what is apparently
> intended as an exact number, 1.65-1.3 (=0.35) to 0.34999999999999987
> but leaves 0.35 unchanged.
[SNIP]
> I admit to be utterly confused by that loss of accuracy and precision.
Are you asking why:
Table[N[165/100, i] - N[13/10, i] === N[35/100, i], {i, 100}]
Exhibits a sudden change in the treatment of numbers when machine precision
is exceeded?
> Additionally, a completely legitimate expression
> 2^^BaseForm[0.35`, 2]
> produces a syntax error message.
Then it is not a legitimate expression. ;-)
Mathematica does perform some naughtinesses with floating-point arithmetic.
Plus[...] is still "orderless" (commutative), even though it shouldn't be
for this arithmetic, e.g. a+b-a == b is not true in general.
Cheers,
Jon.