MathGroup Archive 2004

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

Search the Archive

Re: Exact real numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50576] Re: [mg50501] Exact real numbers
  • From: "Peter Valko" <p-valko at tamu.edu>
  • Date: Fri, 10 Sep 2004 04:06:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Regarding exact real numbers I am suggesting a possible solution:

apprnumber = 1.56012309843;

{rd, m} = RealDigits[apprnumber];
Do[
  rd1 = Take[rd, n];
  rd2 = Take[rd, -(Length[rd] - n)];
  If[FromDigits[{rd2, m}] ? 0.5, Part[rd1, n] += +1];
  Print[{n, FromDigits[{rd1, m}] // N // FullForm}]
  , {n, 1, Length[rd]}]


Results:

{1, 2.`}
{2, 1.6`}
{3, 1.56`}
{4, 1.561`}
{5, 1.5602`}
{6, 1.56013`}
{7, 1.560124`}
{8, 1.5601231`}
{9, 1.5601231`}
{10, 1.560123099`}
{11, 1.5601230985`}
{12, 1.56012309843`}
{13, 1.56012309843`}
{14, 1.56012309843`}
{15, 1.56012309843`}
{16, 1.56012309843`}

Regards
Peter
--------------------------------------------
Peter P. Valko, associate professor
Harold Vance Department of Petroleum Engineering
Texas A&M University
office: 501K Richardson Building (corner of Spence and Ross Streets) 
mail: 3116 TAMU, College Station TX 77843-3116 (USA)
phone: (USA)-(979)-862 2757 
fax: (USA)-(979)-862 1272
web: http://pumpjack.tamu.edu/~valko/
email: p-valko at tamu.edu

------------------------------------------------------------------------
---------------------------
Original message:

Subject: [mg50576] [mg50501] Exact real numbers 
From: Ross Sean Civ AFRL/DELO <sean.ross at kirtland.af.mil> 
To: mathgroup at smc.vnet.net

I have been having an on-going problem with real numbers in Mathematica
that has come up again.  In short, I can find no way of "rounding" a
number in Mathematica.  To me, when I say, round 1.56012309843 to three
decimal places, I want the result to be 1.560 exactly.  No hanging
00000000001's . The reason for this is that I need to do 3-D logic
involving the location of points in space.  I don't like getting faked
out by numbers that ought to be the same but are slighly unequal due to
rounding errors. 

Round only applies to integers.  Multiplying the results of Round by
machine precision reals results in all the hanging digits I want to get
rid of.

SetPrecision and SetAccuracy don't seem to do what I want.
SetPrecision[1.5000287965,5] returns a result with more than 5 digits to
the right of the decimal as does SetAccuracy.

RealDigits is great in that I can actually get a list of all digits and
manipulate them, however, its "inverse" FromDigits returns an F**ing
fraction.  I don't want a fraction.  I want an exact decimal.  I also
prefer function pairs that are exact inverses to one another.

One strange assymetry of Mathematica is that I can type in the exact
decimal number 1.50027` and Mathematica knows that is an exact decimal.
FullForm reveals that the only decimal digits in that number are what I
specified. However, I know of no way to create an exact decimal from a
machine precision one.

Does anyone know of a way to do true decimal rounding in Mathematica?

Please respond to sean.ross at kirtland.af.mil.  I no longer subscribe
to mathgroup.

Dr. Sean Ross
AFRL/DELO
3550 Aberdeen Ave SE, Building 761
Kirtland AFB, NM 87117

phone: 505-846-9148




  • Prev by Date: Re: Re: sorry, but more q's on random numbers
  • Next by Date: Re: parallel NMinimize[]
  • Previous by thread: Re: Exact real numbers
  • Next by thread: Re: Exact real numbers