Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: 34.123*89 = 3036.95 (3036.947)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47909] Re: 34.123*89 = 3036.95 (3036.947)
  • From: "Peltio" <peltio at twilight.zone>
  • Date: Fri, 30 Apr 2004 19:26:49 -0400 (EDT)
  • References: <c6s538$pkf$1@smc.vnet.net>
  • Reply-to: "Peltio" <peltioNOSP at Mdespammed.com.invalid>
  • Sender: owner-wri-mathgroup at wolfram.com

"Thomas Schulz" wrote

>I am a NewBe - and i dont understand the Result.
>Mathematica says that 34.123*89 = 3036.94699999997 but its 3036.947...

There is a very interesting 1993 thread that relate to this. Despite many
things have changed in Mathematica since that date, you might find it useful
to read the insight provided by the late Jerry Keiper and by Roberto Sierra.
Here's the reference for a google groups search:

    From:David Earn (earn*mail.ast.cam.ac.uk)
To: mathgroup at smc.vnet.net
    Object:Arbitrary Precision Floating-Point Arithmetic in mathematica
    Newsgroups:sci.math.symbolic
    Date:1993-12-08 09:19:27 PST

What I write from now on is only my humble point of view.
Since you are working with machine precision numbers (this roughly means 16
digits), when you write 34.123 you are implicitly telling Mathematica to
pick the number whose internal representation is closest to the exact number
34123/1000. What is such a number? Find it yourself with:

    SetPrecision[ 34.123, Infinity ]

It's different from the clean cut fraction 34123/1000, isn't it? That's the
reason you are getting a result that is different from 34123/1000 * 89. Your
result is in fact the decimal expansion (up to 16 digits) of

    SetPrecision[ 34.123, Infinity ] * 89

To see 30 digits of it you can do this:

    N[ SetPrecision[34.123,Infinity], 30 ]

And, as you might have already surmised by now, the first 16 digits are the
same of the result mathematica gave you by working in machine precision.

>How can i change this?

If you want the exact result you have to work with higher or (possibly)
infinite precision. The simplest way, and also the more expensive one I
guess : ), is to work with infinite precision. Rationalize can avoid you to
write the simple fraction equivalent to your decimal number. This is the
result you are after:

    Rationalize[34.123]*89

Watch out, if you use //N you will fall again into the machine precision
swamp and you'll get the number that is closest to that exact number (and
it's not 34.123, sinche that number is not representable in machine
precision). Specifiy a number of digits bigger than your machine precision
(I assumed that it is 16, I do not know the guts of PowerBooks) to _see_
your result:

    N[Rationalize[34.123]*89, 30]

Hope this helps.
cheers,
Peltio
Invalid address in reply-to. Crafty demunging required to mail me.


  • Prev by Date: RE: custom look for the notebook
  • Next by Date: RE: 34.123*89 = 3036.95 (3036.947)
  • Previous by thread: Re: 34.123*89 = 3036.95 (3036.947)
  • Next by thread: RE: 34.123*89 = 3036.95 (3036.947)