MathGroup Archive 2007

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

Search the Archive

Re: Re: MachinePrecission and FPU

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81319] Re: [mg81292] Re: MachinePrecission and FPU
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 19 Sep 2007 05:26:31 -0400 (EDT)
  • References: <fcnl4n$s65$1@smc.vnet.net> <22000609.1190123025413.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

The earlier poster is correct. It's only rounding that causes 5.0 to  
display, since the internal result is (in Mathematica, at least):

RealDigits[0.03/0.006, 2]

{{1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1}, 3}

whereas 5.0 is

RealDigits[5.0, 2]

{{1, 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}, 3}

In decimal, the division result is approximately

RealDigits[0.03/0.006]

{{4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, 1}

or

InputForm[0.03/0.006]

4.999999999999999

Bobby

On Tue, 18 Sep 2007 04:55:15 -0500, Jean-Marc Gulliet  
<jeanmarc.gulliet at gmail.com> wrote:

> dh wrote:
>
>> I could trace down a discrepancy between a C program and Mathematica to  
>> the
>>
>> following. Try to compute 0.03/0.006 and you get 4.9999999.. as neither
>>
>> 0.03 nor 0.006 can be represented accurately, this is not amazing.
>
> On my system (Intel Pentium 4 HT 2.6 MHz), I get consistently 5.0 with
> version 6.0.1 and 5.2.
>
> In[1]:= 0.03/0.006
>
> Out[1]= 5.
>
> In[2]:= $Version
>
> Out[2]= "6.0 for Microsoft Windows (32-bit) (June 19, 2007)"
>
> In[1]:=
> 0.03/0.006
>
> Out[1]=
> 5.
>
> In[2]:=
> $Version
>
> Out[2]=
> 5.2 for Microsoft Windows (June 20, 2005)
>
>> However, the same calculated with C and C++ on PC's gives 5.0000..
>
> /* Very crude C program */
>
> #include <stdio.h>
>
> int main(void)
> {
> 	printf("The value of 0.03/0.006 is %f\n", 0.03/0.006);
>
> 	return 0;
> }
>
> which returns after compilation
>
> The value of 0.03/0.006 is 5.000000
>
>> Now, WHY?
>
> Could that be hardware dependent? You did not mention either the version
> of Mathematica your used or the cpu.
>
> <snip>
>
> Regards,



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Fitting parameters of nonlinear diff equation system
  • Next by Date: Re: Can an arrow be drawn on a 3D plot?
  • Previous by thread: Re: MachinePrecission and FPU
  • Next by thread: Re: MachinePrecission and FPU