[Date Index]
[Thread Index]
[Author Index]
Re: Errors in handling real numbers ?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg8698] Re: Errors in handling real numbers ?
*From*: Paul Abbott <paul at physics.uwa.edu.au>
*Date*: Fri, 19 Sep 1997 02:47:40 -0400
*Organization*: University of Western Australia
*Sender*: owner-wri-mathgroup at wolfram.com
Piotr G. Kin wrote:
> I was trying to develop a function that would return number of digits
> after the decimal point in a real number. The function would work as
> follows:
>
> In[]:= a = 1. 5.1234;
> b = 1. 0.00123;
> c = 1. 0.5;
> digitsafterdot[{a,b,c}]
>
> Out[]= {4,5,1}
I think that you are wanting to work with fixed precision. Note that
you can enter fixed precision numbers using `
In[1]:= a=5.1234`4;
b=0.00123`5;
c=0.5`1;
In[2]:= Precision/@{a,b,c}
Out[2]= {4,5,1}
Note that, since you actually have expressions like a = 1. 5.1234, you
are multiplying a machine precision number by what I think you intend to
be a fixed precision number.
Note that you can force fixed precision by setting
$MaxPrecision=$MinPrecision=n for integral n.
> It gets even funnier with numbers with precision higher than
> $MachinePrecision:
>
> In[]:= x = 0.20000000000000000;
> NestList[FractionalPart[10#] &, x, 5]
> NestList[(10. # - IntegerPart[10. #]) &, x, 5]
By multiplying by 10. you have coerced the precision to machine
precision. Here is your example again:
In[3]:= NestList(FractionalPart(10 #)&,0.12`20,5)
Out[3]=
-19
{0.12000000000000000000, 0.2000000000000000000, 0. 10 ,
-18 -17 -16
0. 10 , 0. 10 , 0. 10 }
In[4]:= NestList(10 #-IntegerPart(10 #)&,0.12`20,5)
Out[4]=
-19
{0.12000000000000000000, 0.2000000000000000000, 0. 10 ,
-18 -17 -16
0. 10 , 0. 10 , 0. 10 }
The results are now equivalent.
>The information in this message is IN-CONFIDENCE and is intended for
>CSIRO personnel only. Distribution of this information to non-CSIRO personnel
>must be authorised in accordance with CSIRO Code of Conduct (Policy 94/18)
And was it?
Cheers,
Paul
____________________________________________________________________
Paul Abbott Phone: +61-8-9380-2734
Department of Physics Fax: +61-8-9380-1014
The University of Western Australia
Nedlands WA 6907 mailto:paul at physics.uwa.edu.au
AUSTRALIA http://www.pd.uwa.edu.au/~paul
God IS a weakly left-handed dice player
____________________________________________________________________
Prev by Date:
**Display and Export of DensityGraphics**
Next by Date:
**Help! How can I control the size of individual point?**
Previous by thread:
**Errors in handling real numbers ?**
Next by thread:
**HTML generation in 3.0.0**
| |