Given SR constant, I want to extract the first L base B digits
of the fractional part.

So far the best solution I found is:
floor((SR(expression)*B**L).numerical_approx(digits=L)).digits(B)

Can I do better?

Why the following approach fails numerically:

```
def base_B_digits(A, B,prot=False):
    digits=[]
    fractional_part = A - int(A)
    while fractional_part != 0:
       digit = int(fractional_part * B)
       digits.append(digit)
       fractional_part = fractional_part * B - digit
       if prot:  print(fractional_part)
    return digits
```
tt=base_B_digits(SR(1/3).numerical_approx(digits=10),10,1)

The fractional part starts:

0.3333333333
0.3333333331
0.3333333314
0.3333333139
0.3333331393
...
0.7812500000
0.8125000000
0.1250000000
0.2500000000
0.5000000000
0.0000000000

I am not sure the program must terminate.

For A=1/4, the base 10 digits are computed correctly.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAGUWgD9HpSwbwyWqc5BWkr4tnOhMfg5avhrRKUZJ7W24DCuATA%40mail.gmail.com.

Reply via email to