MathGroup Archive 2004

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

Search the Archive

Re: creating exact numbers, strange behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52999] Re: [mg52960] creating exact numbers, strange behavior
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sun, 19 Dec 2004 06:14:45 -0500 (EST)
  • References: <200412180859.DAA02167@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Here are Mathematica's binary representations of the numbers in that last Quotient:

RealDigits[7.*10^100,2]
RealDigits[10^100,2]

{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,
     0,0,1,0,1,0,1,1,0,0,0,0,1,1,0,1},336}

{{1,0,0,1,0,0,1,0,0,1,0,0,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0,1,1,0,0,1,0,1,0,0,
     1,1,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,1,1,0,1,0,1,1,0,0,0,0,1,0,1,1,0,0,1,0,
     0,1,1,1,1,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,0,1,1,
     1,1,1,1,0,0,1,1,1,0,0,0,1,0,1,0,1,1,0,0,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,0,
     1,1,1,0,0,0,1,0,0,0,0,1,0,0,0,1,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1,0,
     1,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,
     1,1,1,0,1,0,0,0,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0},333}

Quick, now... what's the quotient and remainder? (Not for the original numbers -- for THOSE numbers.)

For the quotient to be 7, you need 7*10^100 <= 7.*10^100. But check out the binary representations:

real=RealDigits[7.*10^100,2]
integer=RealDigits[7*10^100,2]

{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,
     0,0,1,0,1,0,1,1,0,0,0,0,1,1,0,1},336}

{{1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,
     0,0,1,0,1,0,1,1,0,0,0,0,1,1,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,0,0,1,1,1,0,0,
     0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,1,1,0,0,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,
     0,1,1,1,0,1,0,1,0,0,0,1,1,0,0,1,0,1,1,1,0,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,
     1,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1,0,1,1,1,0,0,1,0,1,1,0,1,0,0,0,1,0,1,0,1,
     0,1,0,1,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,1,1,1,1,0,0,1,0,0,1,1,0,0,1,0,
     1,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0},336}

They agree to the 53 bits precision present in "real":

Length@First@real
First@Take[integer,1,Length@First@real]\[Equal]First@real

53
True

But the "integer" version has other non-zero bits, so the integer version is bigger.

So the quotient isn't 7. It's 6.

Q: What's the solution?
A: If you intend a number to be exactly 7*10^100, write it that way (with no decimal).

Quotient[7*10^100,10^100]

7

Bobby

On Sat, 18 Dec 2004 03:59:33 -0500 (EST), Matthias Gottschalk <gottschalk at gfz-potsdam.de> wrote:

> Hi,
>
> I try to convert machine number into an exact number. I do this the
> following way:
>
> In[] = Quotient[7.*10^30,10^30]
>
> Out[] = 7
>
> that is fine.
>
>
> In[] = Quotient[7.*10^99, 10^99]
>
> Out[] = 7
>
> still fine.
>
>
> In[] = Quotient[7.*10^100,10^100]
>
> Out[] = 6
>
> ????????, I think that is bad.
> Or am I doing something wrong?
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Mathematica language issues
  • Next by Date: Re: Re: Mathematica slows down
  • Previous by thread: creating exact numbers, strange behavior
  • Next by thread: Re: creating exact numbers, strange behavior