**[Sanghabum--aol--com]**wrote:

# Arithmetic precision

### [1/6] from: sanghabum:aol at: 2-Feb-2001 4:50

Is there any way in Rebol that I can extend the number of significant digits
when doing arithmetic?
I'm trying (as a Rebol-learning exercise) to convert some old Rexx code. In
Rexx, the problem is trivial:
<rexx program:>
/* rexx */
a = 1000000001
b = 71
say " default=" a / b
numeric digits 25
say " 25 digit=" a / b
numeric digits 250
say "250 digit=" a / b
</rexx program>
<result>
default= 14084507.1
25 digit= 14084507.05633802816901408
250 digit14084507.056338028169014084507042253521126760563380281690140845070422535211267
605633802816901408450704225352112676056338028169014084507042253521126760563380
281690140845070422535211267605633802816901408450704225352112676056338028169014
08450704225352113
</result>
Thanks,
Colin.

### [2/6] from: gmassar::dreamsoft::com at: 2-Feb-2001 10:20

Colin,
Arithmetic precision in REBOL is only 64 bits long including the exponent
for a decimal! value according to some IEEE standard. I think REXX relies
heavily on so called Math of numbers. For instance, most of divisions have
some repetition in the decimal part. E.g., in your case,
1000000001 / 71 = 14084507.05633802816901408450704225352112676'
The quote mark at the end indicates the repetition. REBOL code below will
produce the precision as long as 250 digits.

>> S: "14084507."
>> R: "05633802816901408450704225352112676"
>> loop 7 [S: join S R] print S

Actually, it is 253 digits long. Compare the result against REXX result
below. That's all I can help you. I majored Math some 35 years ago and I
hardly remembered what I learned.
Geo ...

### [3/6] from: sanghabum:aol at: 3-Feb-2001 6:09

In a message dated 02/02/2001 18:32:44 GMT Standard Time,

**[gmassar--dreamsoft--com]**writes:> Arithmetic precision in REBOL is only 64 bits long including the exponent
> for a decimal! value according to some IEEE standard. I think REXX relies
> heavily on so called Math of numbers. For instance, most of divisions have
> some repetition in the decimal part. E.g., in your case,
<snip>

Thanks for the response. Rexx does all it's arithmetic long hand on strings,
much the same way we learnt at school. Which gives it 10.01 out of 10.01 for
precision, but minus several dozen for speed. Not a language you'd want to
write a spreadsheet in, unless your users were very patient
I thought I'd try thinking more like a Rebol than a Royalist (would that be
an old Rexx supporter?) and try to recast my code using tuples. After all, at
first glance, they seem to offer structured digit strings of arbitrary length.
Unfortunately not. They only have a maximum of 10 parts, and each part must
be less that 256.
These limitations seem arbitrary and bizarre. Am I missing some awesome
subtly of the language? (It wouldn't be the first time).
In the meantime, I'll keep puzzling over how to get an exact result from
something like:
a: 123456789.123456789 - 123456789

### [4/6] from: al:bri:xtra at: 4-Feb-2001 11:35

**[Sanghabum--aol--com]**wrote:

> These limitations seem arbitrary and bizarre. Am I missing some awesome

subtly of the language? (It wouldn't be the first time).
No one has written an arbitrary precision package for Rebol yet. Request it
by sending an email with the details to

**[feedback--rebol--com]**. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/### [5/6] from: gjones05:mail:orion at: 3-Feb-2001 18:40

Hi, Colin,
Colin wrote:

> Is there any way in Rebol that I can extend the number of significant

digits

> when doing arithmetic?

...
Andrew's email reminded me that I had started this message this morning,
then left it unfinished.
Geo pointed out a mathematical principle I had long since forgotten (thanks,
Geo, for "reminding" me that I must suffer from Alzheimer's or Mad Cow
disease, or both! ;-).
Outside of doing higher precision math with strings, there are single
purpose tricks for specific problems. You may already know this and are
simply trying to make a point, for which I will apologize in advance.
For the first example question, using the two original numbers 1000000001
and 71, the whole number portion can be obtained from division. Then obtain
the fractional portion by starting with the remainder function (or //).
Divide this "remainder" by 71. This then represents the fraction portion
and allows more degrees of significance.
Hardly very satisfying, I know. Only a more general purpose unit would
really address the issue.
Out of curiosity, I checked out vbscript and it gave 14084507.056338, the
same level as REBOL. Then I checked Tcl set at it's default precision level
of 12 giving 14084507.0563. Then I set Tcl to its maximum of 17, and
received 14084507.056338029. These scripting languages seem to give
similar, disappointing results if one is looking for high precision math.
Next I checked out the equation 123456789.123456789 - 123456789. VBScript:
0.123456791043282. Tcl(set to its max): 0.12345679104328156. Again, I
think REBOL hits in the same ballpark.
I guess if one can really measure a phenomenon to a degree of precision that
then the math warrants a high precision package, then none of these
pre-baked scripting languages are going to do the trick. I suspect that the
same prinicple is true with most languages, which generally require add-on
units to attack these sorts of problems. Rexx seems special in this regard,
but I know little about. Outside of decreased speed in mathematical
functions, I guess using a string datatype can prove to be more of a
hindrance in other areas.
Well, as always, this information and 35 cents may buy you a phone call, if
you are lucky. Good luck in the search for higher precision!
-Scott

### [6/6] from: g:santilli:tiscalinet:it at: 4-Feb-2001 13:36

Hello

**[Sanghabum--aol--com]**! On 03-Feb-01, you wrote: [tuples] S> Unfortunately not. They only have a maximum of 10 parts, and S> each part must be less that 256. S> These limitations seem arbitrary and bizarre. Am I missing S> some awesome subtly of the language? (It wouldn't be the first S> time). They're used for IP addresses and colors, or anything similar. If you need a generic "array of integers" you can use a block of integers (integer! is 32 bit); or you can use strings as Rexx does. Regards, Gabriele. -- Gabriele Santilli <**[giesse--writeme--com]**> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/