       Re: Puzzled by IntegerPart

• To: mathgroup at smc.vnet.net
• Subject: [mg114641] Re: Puzzled by IntegerPart
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sat, 11 Dec 2010 01:54:41 -0500 (EST)

```On 12/10/10 at 2:29 AM, sebhofer at gmail.com (Sebastian) wrote:

>On Dec 9, 12:00 pm, Themis Matsoukas <tmatsou... at me.com> wrote:
>>IntegerPart[100*1.15]

>>114

>>???

>I was going to say: Mathematica seems to floor numeric quantities
>(which would kindof make sense to me), e.g. In:=
>In:= IntegerPart[100*1.13]
>IntegerPart[100*(1.13 + \$MachineEpsilon)]

>Out= 112

>Out= 113

>In:= Floor[100*1.13]
>Floor[100*(1.13 + \$MachineEpsilon)]

>Out= 112

>Out= 113

>On the other hand...
>In:= IntegerPart[100*1.12]
>IntegerPart[100*(1.12 + \$MachineEpsilon)]
>
>Out= 112

>Out= 112

>In:= Floor[100*1.12]
>Floor[100*(1.12 + \$MachineEpsilon)]

>Out= 112

>Out= 112 ... so I'm also puzzled.

The puzzle is explained by looking at how these values are
represented and understanding what the functions act on.

That is

In:= RealDigits[1.12] == RealDigits[1.12 + \$MachineEpsilon]

Out= True

So, any function working on the decimal digits clearly gets the
same result for both 1.12 and 1.12+\$MachineEpsilon

But note,

In:= RealDigits[1.12, 2] == RealDigits[1.12 +
\$MachineEpsilon, 2]

Out= False

That is adding \$MachineEpsilon does change the binary
representation but does so at bits that not used in the decimal
representation for this particular value. However

In:= RealDigits[1.13] == RealDigits[1.13 + \$MachineEpsilon]

Out= False

So, functions working on the decimal representation for 1.13
will yield a different result when \$MachineEpsilon is added.

The behavior depends on the precise value of the nearest machine
number to whatever decimal input you make.

There are a several tutorials in the documentation that expound
on this further. If you want to research this further a starting
point would be:

tutorial/MachinePrecisionNumbers
ComputerArithmetic/tutorial/ComputerArithmetic

```

• Prev by Date: Re: Replacement Rule with Sqrt in denominator. Also Bug in Series; see Semantica / Harris solution
• Next by Date: Re: Analytics in Version 8.0
• Previous by thread: Re: Puzzled by IntegerPart
• Next by thread: Re: Puzzled by IntegerPart