Re: MachinePrecission and FPU

*To*: mathgroup at smc.vnet.net*Subject*: [mg81310] Re: MachinePrecission and FPU*From*: Andrew Moylan <andrew.j.moylan at gmail.com>*Date*: Wed, 19 Sep 2007 05:20:38 -0400 (EDT)*References*: <fcnl4n$s65$1@smc.vnet.net><46EF98F4.8060601@gmail.com>

Confirmed: InputForm[0.03/0.006] 4.999999999999999 #include <iostream> int main() { std::cout.precision(15); std::cout << std::fixed << (0.03 / 0.006); return 0; } 5.000000000000000 On Sep 18, 7:59 pm, Daniel Huber <d... at metrohm.ch> wrote: > Hy Jean-Marc, > thank's for the response. Note that 0.03/0.006 gives you a rounded > number (OutputForm). If you want to see all digits you have to look at > the InputForm: > 0.03/0.006 //InputForm > it would be interessting to know if with this you may get a different > result. > Daniel > > > > Jean-Marc Gulliet 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, > > -- > > Daniel Huber > Metrohm Ltd. > Oberdorfstr. 68 > CH-9100 Herisau > Tel. +41 71 353 8585, Fax +41 71 353 8907 > E-Mail:<mailto:d... at metrohm.com> > Internet:<http://www.metrohm.ch>