Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1950 > unrolled thread

Re: MachinePrecision vs. Arbitrary Precision

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-04-28 10:34 +0000
Last post2011-04-29 11:30 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: MachinePrecision vs. Arbitrary Precision Bill Rowe <readnews@sbcglobal.net> - 2011-04-28 10:34 +0000
    Re: MachinePrecision vs. Arbitrary Precision Scott Hemphill <hemphill@hemphills.net> - 2011-04-29 11:30 +0000

#1950 — Re: MachinePrecision vs. Arbitrary Precision

FromBill Rowe <readnews@sbcglobal.net>
Date2011-04-28 10:34 +0000
SubjectRe: MachinePrecision vs. Arbitrary Precision
Message-ID<ipbfs7$ad3$1@smc.vnet.net>
On 4/27/11 at 5:39 AM, worthless.trash.junk@gmail.com (Rafael Dunn)
wrote:

>In:=
>N[Sin[Exp[100]]]
>N[Sin[Exp[100]], 1]
>N[Sin[Exp[100]], 11]

>Out:=
>-0.999105
>0.1
>0.14219812366

>I realize that N[exp] = N[exp, MachinePrecision].  This indicates
>when N[] is asked to calculate to MachinePrecision,

More specifically, this asks hardware to do the required computation.

>it produces an incorrect result in this example.

That is due to the limitations of floating point arithmetic as
implemented in hardware. The actual result you get will vary
according to what hardware is being used.

>However, when I use N[exp,n] where n < MachinePrecision, I get a
>correct output.  Is this because N[exp,n] uses ExtraPrecision, while
>N[exp] does not?

The key is whenever you use N[expr, n], you invoke Mathematica's
arbitrary precision arithmetic and Mathematica does what is
needed to get the desired precision. This often means the result
returned is more accurate than what you get from N[expr] even
when n is less than $MachinePrecision. And note, doing

N[expr, $MachinePrecision]

is quite different than doing either

N[expr]

or

N[expr, MachinePrecision]

[toc] | [next] | [standalone]


#1975

FromScott Hemphill <hemphill@hemphills.net>
Date2011-04-29 11:30 +0000
Message-ID<ipe7h9$qt8$1@smc.vnet.net>
In reply to#1950
Bill Rowe <readnews@sbcglobal.net> writes:

> On 4/27/11 at 5:39 AM, worthless.trash.junk@gmail.com (Rafael Dunn)
> wrote:
>
>>In:=
>>N[Sin[Exp[100]]]
>>N[Sin[Exp[100]], 1]
>>N[Sin[Exp[100]], 11]
>
>>Out:=
>>-0.999105
>>0.1
>>0.14219812366
>
>>I realize that N[exp] = N[exp, MachinePrecision].  This indicates
>>when N[] is asked to calculate to MachinePrecision,
>
> More specifically, this asks hardware to do the required computation.
>
>>it produces an incorrect result in this example.
>
> That is due to the limitations of floating point arithmetic as
> implemented in hardware. The actual result you get will vary
> according to what hardware is being used.

To emphasize that this is the result from hardware here is a program in
the C programming language:

  #include <stdio.h>
  #include <math.h>
  int main(void)
  {
    printf("%g\n", sin(exp(100)));
    return 0;
  }

And here is its output:

  -0.999105

Scott
-- 
Scott Hemphill	hemphill@alumni.caltech.edu
"This isn't flying.  This is falling, with style."  -- Buzz Lightyear

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web