MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Puzzled by IntegerPart

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114712] Re: Puzzled by IntegerPart
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 13 Dec 2010 06:35:07 -0500 (EST)
  • Reply-to: hanlonr at cox.net

I agree that just increasing the precision is insufficient and that IntegerPart[100*1.15`20] was just a fluke. Rationalize is much more reliable. However, you should extend the precision of 1.15 not the product. 

{#, num = 100*ToExpression[ToString[1.15] <> "`" <> ToString[#]],
    Style[num = IntegerPart[num],
     If[num == 114, Red, Black]]} & /@ Range[5, 50] // Grid


Bob Hanlon

---- Barrie Stokes <Barrie.Stokes at newcastle.edu.au> wrote: 

=============
Hi Bob

The problem for Themis is not explained, even if resolved by  IntegerPart[Rationalize[...]], I think:

num =100*1.15
%//FullForm
IntegerPart[num]
num =100*1.15`20
%//FullForm
IntegerPart[num]
num =100*1.15`21
%//FullForm
IntegerPart[num]
num =100*1.15`22
%//FullForm
IntegerPart[num]
num =100*1.15`50
%//FullForm
IntegerPart[num]
num =100*1.15`100
%//FullForm
IntegerPart[num]

What happens in my PC at 22 (and more) that IntegerPart[num] gives 114 again??

A bigger picture is given by

Table[ {ndp, 
   num = ToExpression[ 
     StringTake[  ToString[ 100*1.15 // Hold ], {6, 13}] <> "`" <> 
      ToString[ ndp ] ], FullForm[num], IntegerPart[ num ]}, {ndp, 5, 
   50, 1} ] // MatrixForm

Barrie

>>> On 10/12/2010 at 6:32 pm, in message <201012100732.CAA06914 at smc.vnet.net>, Bob
Hanlon <hanlonr at cox.net> wrote:
> 100*1.15
> 
> 115.
> 
> % // InputForm
> 
> 114.99999999999999
> 
> Increase input precision
> 
> IntegerPart[100*1.15`20]
> 
> 115
> 
> IntegerPart[Rationalize[100*1.15]]
> 
> 115
> 
> 
> Bob Hanlon
> 
> ---- Themis Matsoukas <tmatsoukas at me.com> wrote: 
> 
> =============
> IntegerPart[100*1.15]
> 
> 114
> 
> ???
> 
> Themis




  • Prev by Date: Re: Calculate a numerical integral with enough precision
  • Next by Date: CCP packing of spheres in icosahedron & cuboctahedron
  • Previous by thread: Re: Puzzled by IntegerPart
  • Next by thread: Re: Puzzled by IntegerPart