## #351 DIGIT(s) not being honored

open
Mark Hessling
5
2011-08-18
2011-08-18
No

digits() is 9 [the default].

A number is computed (2* *1387), and the product contains an "E".

So, it is parsed, finding the exponent, adding 2 to it, then NUMERIC DIGITS is set (to419)..

The 1st step is done again (2**1387).

The product still contains an "E".

Strangely, if the DO K=2 ... is recoded to DO K=4 to 4
the REXX program works.

______________________________ Gerard Schildberger

/**/ j=1387
g=1 19 73 1387 /*proper divisors of J.*/
say 'j='j ' g='g

do k=2 to words(g)
gd=word(g,k)
say '----------------------------k='k ' gd='gd
p=2**gd
say '1st p='p
say 'digits='digits()
if pos('E',p)\==0 then do
say 'p has an "E".'
parse var p 'E' pe
say 'pe='pe
numeric digits pe+2
say 'new digits='digits()
p=2**gd
say '2nd p='p
say 'digits='digits()
end
p=p-2
say 'remainder=' p//gd
end

/*end of REXX program.*/

## Discussion

•
Attachments
• A screen scraping from the oopsay's output is (between the ====== fences):

===================================================

D:\&gt;regina oopsay
j=1387 g=1 19 73 1387
----------------------------k=2 gd=19
1st p=524288
digits=9
remainder= 0
----------------------------k=3 gd=73
1st p=9.44473296E+21
digits=9
p has an "E".
pe=+21
new digits=23
2nd p=9444732965739290427392
digits=23
remainder= 0
----------------------------k=4 gd=1387
1st p=3.37756710E+417
digits=23
p has an "E".
pe=+417
new digits=419
2nd p=3.3775671023874658381948E+417
digits=419
remainder= 724

D:\&gt;

===================================================

___________________________________ Gerard Schildberger

• Toby Thurston
2012-11-19

This appears to be related to some loop caching effect in the power "**" function.

For example this

/* Demonstrate digits() / power bug in Regina */
x = 3.141592653589793238462643383
do i=9 to 21 by 3
numeric digits i
say 'Digits:' digits() 'x:' x/1 'x^2:' x**2
end

produces

Digits: 9 x: 3.14159265 x^2: 9.8696044
Digits: 12 x: 3.14159265359 x^2: 9.86960440
Digits: 15 x: 3.14159265358979 x^2: 9.86960440
Digits: 18 x: 3.14159265358979324 x^2: 9.86960440
Digits: 21 x: 3.14159265358979323846 x^2: 9.86960440
REXX-Regina_3.7 5.00 14 Oct 2012

ie the value of x**2 appears to ignore an increase in the value of DIGITS

In contrast *decreases* in DIGITS are respected, if we reverse the order of the above loop we get

igits: 21 x: 3.14159265358979323846 x^2: 9.86960440108935861883
Digits: 18 x: 3.14159265358979324 x^2: 9.86960440108935862
Digits: 15 x: 3.14159265358979 x^2: 9.86960440108936
Digits: 12 x: 3.14159265359 x^2: 9.86960440108
Digits: 9 x: 3.14159265 x^2: 9.8696044
REXX-Regina_3.7 5.00 14 Oct 2012

which appears correct.