-
Notifications
You must be signed in to change notification settings - Fork 11
/
test-unum.py
93 lines (87 loc) · 2.81 KB
/
test-unum.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
import sys
import unum_config
unum_config.e = 0
unum_config.f = 0
from unum import *
#import unum
"""
for i in range(0, 16):
assert view(i) == view(g2u(u2g(i)))
for i in range(0,16):
print bin(i), view(i)
for i in range(0,16):
for j in range(0, 16):
print view(i) + " * " + view(j) + " = " + view(timesu(i, j))
for i in range(0,16):
for j in range(0, 16):
print view(i) + " + " + view(j) + " = " + view(timesu(i, j))
for i in range(0,16):
for j in range(0, 16):
print view(i) + " / " + view(j) + " = " + view(divideu(i, j))
walpri = {}
for i in range(0, 16):
for j in range(0, 16):
if uQ((i, j)):
walpri[view((i,j))] = (i,j)
print len(walpri)
for w in sorted(walpri):
print w
for i in walpri.values():
for j in walpri.values():
print view(i) + " + " + view(j) + " = " + view(plusu(i, j))
sys.exit(1)
"""
unum_config.e = 3
unum_config.f = 4
import unum
reload(unum)
from unum import *
print view(g2u(((Fraction(-1457, 512), Fraction(-134, 1)), (True, False))))
sys.exit(1)
print e
print u2g(5)
print view(x2u(5))
five = x2u(34.2)
print view(five)
def print_unum(u):
print sign(u), expovalue(u), hidden(u), Fraction(frac(u), 2**fsize(u))
print_unum(five)
print frac(five), fsize(five)
print "numbits", numbits(five), "of", maxubits, fsize(five), "of", fsizemax, esize(five), "of", esizemax
print u2f(five)
print x2u(5)
print u2g(x2u(9005))
print plusg(u2g(x2u(34.2)), u2g(x2u(0)))
print 'times', u2f(x2u(34.2)), u2f(x2u(1))
print 'times', timesg(u2g(x2u(34.2)), u2g(x2u(1)))
print view(plusu(x2u(34.2), x2u(0)))
print view(x2u(34.2)), view(timesu(x2u(34.2), x2u(2)))
print view(x2u(34.2)), view(timesu(divideu(x2u(34.2), x2u(2)), x2u(2)))
print view(squareu(x2u(-5)))
#print view(polyu((x2u(5), x2u(6), x2u(1)), x2u(34.2)))
print 'final'
#print view(polyu((x2u(-5), x2u(6), x2u(1)), g2u(((float('-inf'), float('inf')), (True, True)))))
assert promotee(16) == 32
#t = polyu((x2u(-5), x2u(6), x2u(1)), (4294967038, 896))
#ref = g2u(((-14, float('inf')), (False, True)))
#assert sameuQ(t, ref)
#print view(t), view(ref)
print view((4294967038, 896))
print view(sqrtu(x2u(4)))
#print neginfu, posinfu
print view(sqrtFraction(Fraction(10000, 1)))
#x = solveforub(((neginfu, posinfu),), lambda ub: nnequQ(polyu((x2u(-5), x2u(6), x2u(1)), ub), x2u(0)))
#x = solveforub(((x2u(-10), x2u(10)),), lambda ub: nnequQ(polyu((x2u(-5), x2u(6), x2u(1)), ub), x2u(0)))
#print [view(i) for i in x]
unum_config.e = 2
unum_config.f = 3
import unum
reload(unum)
from unum import *
print 'k'
polyu((x2u(4), x2u(8), x2u(1), x2u(-5), x2u(-1), x2u(1)), g2u(((-510, 0), (True, True))))
print 'q'
x = solveforub(((neginfu, posinfu),), lambda ub: nnequQ(polyu((x2u(4), x2u(8), x2u(1), x2u(-5), x2u(-1), x2u(1)), ub), x2u(0)))
print [view(i) for i in x]
print x, [x2u(-1), x2u(2)]
assert x == ((x2u(-1),), (x2u(2),))