-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpcomp.py
111 lines (103 loc) · 2.91 KB
/
mpcomp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import random
import mpmath.libmp
from mpmath import *
from mpap import mpap
#from ArbitraryPrecision import ArbitraryPrecision
EPS = '1e-94'
mp.dps=100
print ("MPMATH backend is ", mpmath.libmp.BACKEND)
m = 101000000000000000000000
m = random.randint(1000, m)
r1 = random.randint(1000, m)
badCount = 0
for i in range (50):
x=mpf(r1)
z=mpap(r1)
x *= x*(-1)
z *= z*(-1)#/(mpap(i+1)*mpap(i+2))
#print (y)
#print (repr(z))
delta = z-mpap(str(x))
#print ("i = ", i, "mpap diff = ", repr(delta))
if abs(delta) > mpap(EPS):
badCount += 1
#print ("---------------------------------------------- BAD ")
#print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
m = max(r1, m)
r1 = random.randint(1000, m)
print ("1. badCount is = ", badCount)
m = random.randint(1000, m)
r1 = random.randint(1000, m)
r2 = random.randint(1000, m)
badCount = 0
for i in range (50):
x = mpf(r1+i+1)/mpf(r2+i+2)
z = mpap(r1+i+1)/mpap(r2+i+2)
#print (x)
#print (repr(z))
delta = z-mpap(str(x))
#print ("i = ", i, "mpap diff = ", repr(delta))
if abs(delta) > mpap(EPS):
badCount += 1
#print ("---------------------------------------------- BAD ")
#print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
m = max(r1, m)
r1 = random.randint(1000, m)
r2 = random.randint(1000, m)
print ("2. badCount is = ", badCount)
m = random.randint(1000, m)
r1 = random.randint(1000, m)
r2 = random.randint(1000, m)
badCount = 0
for i in range (50):
x = (mpf(r1+i+1)/mpf(r2+i+2))**3
z = (mpap(r1+i+1)/mpap(r2+i+2))**3
#print (x)
#print (repr(z))
delta = z-mpap(str(x))
#print ("i = ", i, "mpap diff = ", repr(delta))
if abs(delta) > mpap(EPS):
badCount += 1
#print ("---------------------------------------------- BAD ")
#print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
m = max(r1, m)
r1 = random.randint(1000, m)
r2 = random.randint(1000, m)
print ("3. badCount is = ", badCount)
badCount = 0
for i in range (50):
r1 = random.randint(5001, 100000)
r2 = random.randint(1001, 5000)
a = r1/r2
print ("a is ", a)
x = mp.exp(a)
z = mpap(a).exp()
print ("x: ", x)
print ("z: ", repr(z))
delta = z-mpap(str(x))
#print ("i = ", i, "mpap diff = ", repr(delta))
if abs(delta) > mpap(EPS):
badCount += 1
print ("---------------------------------------------- BAD ")
#print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
## NOTE -- MPAP EXP matches with LibBF -- looks like MPMath
## is not using gmpy2 backend correctly
print ("4. EXP. badCount is = ", badCount)
badCount = 0
for i in range (50):
r1 = random.randint(5001, 1000000)
r2 = random.randint(1001, 5000)
a = r1/r2
print ("a is ", a)
x = mp.tan(a)
z = mpap(a).tan()
print ("x: ", x)
print ("z: ", repr(z))
delta = z-mpap(str(x))
#print ("i = ", i, "mpap diff = ", repr(delta))
if abs(delta) > mpap(EPS):
badCount += 1
print ("---------------------------------------------- BAD ")
#print ('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
## NOTE -- MPAP EXP matches with LibBF
print ("4. TAN. badCount is = ", badCount)