Re: bug in IntegerPart ?
- To: mathgroup at smc.vnet.net
- Subject: [mg47769] Re: bug in IntegerPart ?
- From: ancow65 at yahoo.com (AC)
- Date: Mon, 26 Apr 2004 02:41:13 -0400 (EDT)
- References: <c6g015$4lk$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"DrBob" <drbob at bigfoot.com> wrote in message news:<c6g015$4lk$1 at smc.vnet.net>... > There's NO reason to be puzzled. 1.65 and 1.3 can't be represented exactly > in binary, so of course their difference may not be exact, either. Hence the > division problems have different numerators. Your 'explanation' makes no sense whatsoever. Mathematica's binary representations of 1.65-1.3 and 0.35 are the same. That can be seen by comparing BaseForm[1.65 - 1.3, 2] with BaseForm[0.35,2] 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. Here is an additional reason for concerns. {Accuracy[#], Precision[#]} &[0.35] => {16.4105, MachinePrecision} BaseForm[0.35, 2] => 0.010110011001100110011 (n = 2^^0.010110011001100110011 ) => 0.350000 Notice the unussual display of trailing zeros. {Accuracy[#], Precision[#]} &[n] => {6.32163, 5.8657} I admit to be utterly confused by that loss of accuracy and precision. Additionally, a completely legitimate expression 2^^BaseForm[0.35`, 2] produces a syntax error message. > > RealDigits[0.35, 2] > {{1, 0, 1, 1, 0, 0, 1, 1, 0, > 0, 1, 1, 0, 0, 1, 1, 0, 0, > 1, 1, 0, 0, 1, 1, 0, 0, 1, > 1, 0, 0, 1, 1, 0, 0, 1, 1, > 0, 0, 1, 1, 0, 0, 1, 1, 0, > 0, 1, 1, 0, 0, 1, 1, 0}, > -1} > RealDigits[1.65 - 1.3, 2] > {{1, 0, 1, 1, 0, 0, 1, 1, 0, > 0, 1, 1, 0, 0, 1, 1, 0, 0, > 1, 1, 0, 0, 1, 1, 0, 0, 1, > 1, 0, 0, 1, 1, 0, 0, 1, 1, > 0, 0, 1, 1, 0, 0, 1, 1, 0, > 0, 1, 1, 0, 0, 1, 0, 0}, > -1} > > DrBob > > www.eclecticdreams.net > > > -----Original Message----- > From: Dennis de Lang [mailto:lang.NO at science.uva.nl] To: mathgroup at smc.vnet.net > Subject: [mg47769] bug in IntegerPart ? > > Why does the following happen? > > In[1]:= (1.65 - 1.3)/0.007 > Out[1]:= 50. > In[2]:= IntegerPart[%] > Out[2]:= 49 > > but: > > In[1]:= 0.35/0.007 > Out[1]:= 50. > In[2]:= IntegerPart[%] > Out[2]:= 50 > > I'm puzzled.... > - Dennis
- Follow-Ups:
- Re: Re: bug in IntegerPart ?
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Re: bug in IntegerPart ?
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: bug in IntegerPart ?