Professional Documents
Culture Documents
formula).
#Ported from the c implementation by David H. Bailey. It allows the nth
digit of
#pi to be calculated without calculating the n-1 digits before. This method
holds
#advantages over alternative method of calculating Pi. Such as a small
memory
#footprint that does not increase. Output is an array of hexadecimal values
where
#the number of correct values after the nth digit is dependent on floating
point
#precisions.
#
#“On most systems using IEEE 64-bit floating-
# Point arithmetic, this code works correctly so long as d is less than
# Approximately 1.18 x 10^7. If 80-bit arithmetic can be employed, this
limit
# is significantly higher. Whatever arithmetic is used, results for a
given
# position id can be checked by repeating with id-1 or id+1, and
verifying
# that the hex digits perfectly overlap with an offset of one, except
possibly
# for a few trailing digits. The resulting fractions are typically
accurate
# to at least 11 decimal digits, and to at least 9 hex digits” – from
David H.
# Bailey’s notes on implementation.
def hexpi_nth_digits(id):
s1 = float(series(1, id))
s2 = float(series(4, id))
s3 = float(series(5, id))
s4 = float(series(6, id))
# This returns, in chx, the first nhx hex digits of the fraction of x.
hx = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"]
y = float(abs(x))
chx = range(nhx)
return chx
def series(m,id):
s =0.0
ak=0.0
p=0.0
s=0.0
t=0.0
eps = float((10**(-17)))
return s
def expm(p,ak):
ntp = 25
exi = 0
p1 = 0.0
pt = 0.0
r = 0.0
tp1 = 1
tp = range(ntp)
if (tp1 == 0):
tp1 = 1
tp[0] = 1.0
exi = ntp
for i in range(1, ntp):
exi = i
if (tp[i] > p):
break
pt = float(tp[exi-1])
p1 = p
r = 1.0
return r