Published
Edited
Apr 15, 2020
Insert cell
Insert cell
import {pyPN} from "@andrzejq/pnlib-brython-python-source"
Insert cell
{ // PNlib_Br with tests v.0.0
pyPN`
#@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@#

def test_(x,pattern):
r = repr(x)
print(r)
assert r == pattern, f'''{r} != {pattern}'''


test_( f'''PolyNumConf_sep:::{PolyNumConf_sep}''',"""'PolyNumConf_sep:::~'""")
test_(f'''flt:::{flt('3.141516171819202122')}''',"""'flt:::3.141516171819202'""")
test_(f'''strF:::{strF(3.141516171819202122)}''',"""'strF:::3.141516172'""")

test_(f'''pi={pi}, exp(1)={exp(1)}''',"""'pi=3.141592653589793, exp(1)=2.718281828459045'""")
test_(f'''sqrt(1/2)={sqrt(1/2)}, sqrt(2)={sqrt(2)}''',"""'sqrt(1/2)=0.7071067811865476, sqrt(2)=1.4142135623730951'""")

test_(f'''erfc(0)={erfc(0)} erfc(1)={erfc(1)} erfc(4)={erfc(4)} erfc(8)={erfc(8)}''',"""'erfc(0)=1.0 erfc(1)=0.15729920705028522 erfc(4)=1.5417256640789805e-8 erfc(8)=1.1224297172982929e-29'""")
test_(f'''erfc(-1)={erfc(-1)} erfc(-4)={erfc(-4)} erfc(-8)={erfc(-8)}''',"""'erfc(-1)=1.8427007929497148 erfc(-4)=1.9999999845827434 erfc(-8)=2.0'""")

print( '#@@@ init','@'*22 )
print( '#@@@ - PN zero')

test_( PolyNum(),"""PolyNum('(~0.0~)')""")
print( '#@@@ - PN from string:')
test_( PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(-2)') ,"""PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(-2)')""")
test_( PolyNum('(~1.2~)') ,"""PolyNum('(~1.2~)')""")
test_( PolyNum('(~0~,2.5~-0.3~)') ,"""PolyNum('(~2.5~,-0.3~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~,2.5~-0.3~)') ,"""PolyNum('(~2.5~,-0.3~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~-1.1~2.2~,-3.3~)') ,"""PolyNum('(~-1.1~,2.2~-3.3~)*(~1~0~)**(1)')""")

print( '#@@@ - PN const from string:')
y1=PolyNum('const:(~2~,-4~4~-4~4~...~)'); y1._strPN_cut = 7;
test_( y1 ,"""PolyNum('(~2~,-4~4~-4~4~-4~4~...~)')""")
y2=PolyNum('const:(~1~,2~2~2~2~...~)'); y2._strPN_cut = 7;
test_( y2 ,"""PolyNum('(~1~,2~2~2~2~2~2~...~)')""")
print( '#@@@ - PN matissa and exponent')
p1 = PolyNum([1.1,2,3],-2);
test_( p1 ,"""PolyNum('(~1.1~,2~3~)*(~1~0~)**(-2)')""")
test_( p1.asList()[:10] ,"""[0.0, 0.0, 1.1, 2, 3, 0.0, 0.0, 0.0, 0.0, 0.0]""")
test_( p1.asPointsList(h=0.5)[:10] ,"""[[0.0, 0.0], [0.5, 0.0], [1.0, 1.1], [1.5, 2], [2.0, 3], [2.5, 0.0], [3.0, 0.0], [3.5, 0.0], [4.0, 0.0], [4.5, 0.0]]""")
test_( p1.asPointsList(h=0.5,t_offs=3)[:10] ,"""[[3.0, 0.0], [3.5, 0.0], [4.0, 1.1], [4.5, 2], [5.0, 3], [5.5, 0.0], [6.0, 0.0], [6.5, 0.0], [7.0, 0.0], [7.5, 0.0]]""")

p2 = PolyNum(p1, 12);
test_( p2 ,"""PolyNum('(~1.1~,2~3~)*(~1~0~)**(10)')""")
# test_( p2.asList()[:10] ,"""[0.0, 0.0, 1.1, 2, 3, 0.0, 0.0, 0.0, 0.0, 0.0]""")
# Error: PN exponent = 10. Can not convert to array if PN exponent > 0

pM0 = PolyNum([1.1,2,3]);
test_( pM0 ,"""PolyNum('(~1.1~,2~3~)')""")
test_( PolyNum([1,2.0,3]) ,"""PolyNum('(~1~,2.0~3~)')""")
test_( ( PolyNum([3+zeroPNdig,2,onePNdig]) ) ,"""PolyNum('(~3.0~,2~1.0~)')""")
test_( PolyNum([0,0,3,4]) ,"""PolyNum('(~3~,4~)*(~1~0~)**(-2)')""")
test_( PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(-2)') ,"""PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(-2)')""")
test_( PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(2)') ,"""PolyNum('(~1.2~,2.5~-0.3~)*(~1~0~)**(2)')""")
test_( PolyNum('(~1.2~,2.5~-0.3~)') ,"""PolyNum('(~1.2~,2.5~-0.3~)')""")
test_( PolyNum('(~1.2~)') ,"""PolyNum('(~1.2~)')""")

# BRYTHON ERROR
test_( PolyNum('(~0.1~,2e-38~4.3~6.1e-10~)').chop(),"""PolyNum('(~0.1~,0.0~4.3~6.1e-10~)')""")
test_( PolyNum('(~1e-36~,2e-38~4.3~6.0~)').chop() ,"""PolyNum('(~4.3~,6.0~)*(~1~0~)**(-2)')""")

print( '#@@@ call','@'*22 )
p = PolyNum([3.,0,1,2])
test_( p(5.) ,"""3.056""")# 3. * 5.**0 + 0 * 5.**(-1)1 + 1 * 5.**(-2) + 2 * 5.**(-3)
p1 = PolyNum([3.,0,1,2],-2)
test_( p1(5.) ,"""0.12224""")

print( '#@@@ __mul__','@'*22 )
test_( PolyNum([1.,2,3],-2) * 100 ,"""PolyNum('(~100.0~,200~300~)*(~1~0~)**(-2)')""")
test_( PolyNum([1.,2,3],-2) * PolyNum([0.1,2],-5) ,"""PolyNum('(~0.1~,2.2~4.3~6.0~)*(~1~0~)**(-7)')""")
test_( PolyNum([0.1,2],-5) * PolyNum([1.,2,3],-2) ,"""PolyNum('(~0.1~,2.2~4.3~6.0~)*(~1~0~)**(-7)')""")
test_( 100 * PolyNum([1.,2,3],-2) ,"""PolyNum('(~100.0~,200~300~)*(~1~0~)**(-2)')""")#__rmul__ test
p1 = PolyNum([1.,2,3],-2) #__imul__ test
p1 *= PolyNum([0.1,2],-5)
test_( p1 ,"""PolyNum('(~0.1~,2.2~4.3~6.0~)*(~1~0~)**(-7)')""")
p100 = 100. #__imul__ test
p100 *= PolyNum([0.1,2],-5)
test_( p100 ,"""PolyNum('(~10.0~,200.0~)*(~1~0~)**(-5)')""")
## test_( p1 * [1,2,3,4] ,"""Traceback (most recent call last):""")
# ...
# ValueError: [1, 2, 3, 4] <- invalid operand for PN __mul__
## test_( [5,6,7] * p1 ,"""Traceback (most recent call last):""")
# ...
# ValueError: [5, 6, 7] <- invalid operand for PN __rmul__

print( '#@@@ __truediv__','@'*22 )

y1 = PolyNum([1.,0.2,0.3],-2) / PolyNum([0.1,0.2],-5)
y1._strPN_cut = 7;
test_( str(y1) ,"""'(~10.0~,-18.0~39.0~-78.0~156.0~-312.0~624.0~...~)*(~1~0~)**(3)'""")
y2 = PolyNum('(~0.1~,0.2~)',-5) / PolyNum('(~1.~,0.2~0.4~)',-2)
y2._strPN_cut = 7;
test_( str(y2) ,"""'(~0.1~,0.18~-0.076~-0.0568~0.04176~0.014368~-0.0195776~...~)*(~1~0~)**(-3)'""")
test_( PolyNum([1.,0.2,0.3],-2) / 100 ,"""PolyNum('(~0.01~,0.002~0.003~)*(~1~0~)**(-2)')""")
y3 = 100 / PolyNum('(~1.~,0.2~0.3~)',-2) #__rdiv__ test
y3._strPN_cut = 7;
test_( y3 ,"""PolyNum('(~100.0~,-20.0~-26.0~11.200000000000001~5.56~-4.472~-0.7736~...~)*(~1~0~)**(2)')""")
p1 = PolyNum([1.,0.2,0.3],-2) #__idiv__ test
p1 /= PolyNum([0.1,0.2],-5)
p1._strPN_cut = 7;
test_( p1 ,"""PolyNum('(~10.0~,-18.0~39.0~-78.0~156.0~-312.0~624.0~...~)*(~1~0~)**(3)')""")
p100 = 100. #__idiv__ test
p100 /= PolyNum([0.1,0.2],-5)
p100._strPN_cut = 7;
test_( p100 ,"""PolyNum('(~1000.0~,-2000.0~4000.0~-8000.0~16000.0~-32000.0~64000.0~...~)*(~1~0~)**(5)')""")
## test_( p1 / [2,3,4] ,"""Traceback (most recent call last):""")
# ...
# ValueError: [2, 3, 4] <- invalid operand for PN __div__
## test_( [3,4,5] / p1 ,"""Traceback (most recent call last):""")
# ...
# ValueError: [3, 4, 5] <- invalid operand for PN __rdiv__

print( '#@@@ __add__','@'*22 )
test_( PolyNum('(~1~,2~3~)') + PolyNum('(~10~,20~30~)') ,"""PolyNum('(~11.0~,22.0~33.0~)')""")
test_( PolyNum('(~1~,2~3~)*(~1~0~)**(-3)') + PolyNum('(~10~,20~30~)*(~1~0~)**(-1)') ,"""PolyNum('(~10.0~,20.0~31.0~2.0~3.0~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~1~,2~3~)*(~1~0~)**(-3)') + 100 ,"""PolyNum('(~100.0~,0.0~0.0~1.0~2.0~3.0~)')""")
test_( PolyNum('(~1~2~3~)') + 100 ,"""PolyNum('(~1.0~,2.0~103.0~)*(~1~0~)**(2)')""")
test_( 100 + PolyNum([1.,2,3],-2) ,"""PolyNum('(~100.0~,0.0~1.0~2~3~)')""")#__radd__ test
p1 = PolyNum([1.,2,3],-2) #__iadd__ test
p1 += PolyNum([0.1,5],-4)
test_( p1 ,"""PolyNum('(~1.0~,2.0~3.1~5.0~)*(~1~0~)**(-2)')""")
p100 = 100. #__iadd__ test
p100 += PolyNum([0.1,2],-4)
test_( p100 ,"""PolyNum('(~100.0~,0.0~0.0~0.0~0.1~2.0~)')""")

print( '#@@@ __sub__','@'*22 )
test_( PolyNum('(~1~,2~3~)') - PolyNum('(~10~,20~30~)') ,"""PolyNum('(~-9.0~,-18.0~-27.0~)')""")
test_( PolyNum('(~1~,2~3~)*(~1~0~)**(-3)') - PolyNum('(~10~,20~30~)*(~1~0~)**(-1)') ,"""PolyNum('(~-10.0~,-20.0~-29.0~2.0~3.0~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~1~,2~3~)*(~1~0~)**(-3)') - 100 ,"""PolyNum('(~-100.0~,0.0~0.0~1.0~2.0~3.0~)')""")
test_( PolyNum('(~1~2~3~)') - 100 ,"""PolyNum('(~1.0~,2.0~-97.0~)*(~1~0~)**(2)')""")
test_( 100 - PolyNum([1.1,2,3],-2) ,"""PolyNum('(~100.0~,0.0~-1.1~-2~-3~)')""")#__rsub__ test
p1 = PolyNum([1.1,2.5,3],-2) #&... #__isub__ test
p1 -= PolyNum([0.1,5.1],-4)
test_( p1 ,"""PolyNum('(~1.1~,2.5~2.9~-5.1~)*(~1~0~)**(-2)')""")
p100 = 100. #__isub__ test
p100 -= PolyNum([0.1,2],-4)
test_( p100 ,"""PolyNum('(~100.0~,0.0~0.0~0.0~-0.1~-2.0~)')""")

print( '#@@@ __pow__','@'*22 )

xx = PolyNum('(~0.1~,2.0~)')
y0 = 1 / xx ; y0._strPN_cut = 5
test_( y0 ,"""PolyNum('(~10.0~,-200.0~4000.0~-80000.0~1600000.0~...~)')""")

y_02 = y0**(-2) ;y_02._strPN_cut = 5
test_( y_02 ,"""PolyNum('(~0.01~,0.4~4.0~0.0~0.0~...~)')""")
y_03 = y0**(3) ;y_03._strPN_cut = 5
test_( y_03 ,"""PolyNum('(~1000.0~,-60000.0~2400000.0~-79999999.999999985098839~2400000000.0~...~)')""")

y_002 = xx**(1/2) ;y_002._strPN_cut = 5
y_002_ = xx.sqrt() ;y_002_._strPN_cut = 5
test_( y_002 ,"""PolyNum('(~0.316227766016838~,3.162277660168379~-15.811388300841895~158.113883008418924~-1976.423537605236561~...~)')""")
test_( y_002_ ,"""PolyNum('(~0.316227766016838~,3.162277660168379~-15.811388300841895~158.113883008418981~-1976.423537605236561~...~)')""")
y_003 = y0**(1/3) ;y_003._strPN_cut = 5
test_( y_003 ,"""PolyNum('(~2.154434690031884~,-14.36289793354589~191.505305780611849~-2978.971423253961348~49649.523720899378532~...~)')""")

y1 = xx **(-1)
y1._strPN_cut = 5
test_( y1 ,"""PolyNum('(~10.0~,-200.0~4000.0~-80000.0~1600000.0~...~)')""")
print('-- 1 ----------')
y0xx = (y0 * xx); y0xx._strPN_cut = 22;
test_( y0xx ,"""PolyNum('(~1.0~,0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~...~)')""")
y1xx = (y1 * xx); y1xx._strPN_cut = 22;
test_( y1xx ,"""PolyNum('(~1.0~,0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~0.0~...~)')""")

print( '#@@@ __abs__','@'*22 )
test_( abs(PolyNum('(~2.4~,-1.1~-8.8~)')) ,"""PolyNum('(~2.4~,1.1~8.800000000000001~)')""")


print( '#@@@ isnonnegative','@'*22 )
x = PolyNum('(~2.4~,-1.1~-8~)')
test_( x.isnonnegative() ,"""False""")
test_( abs(x).isnonnegative() ,"""True""")
test_( PolyNum(0.0).isnonnegative() ,"""True""")
print( '#@@@ __le__','@'*22 )
x = PolyNum('(~2.4~,-1.1~-8~)')
test_( x <= x ,"""True""")
test_( x <= abs(x) ,"""True""")
test_( x <= 2*x ,"""False""")
test_( abs(x) <= 2*abs(x) ,"""True""")

print( '#@@@ __ge__','@'*22 )
x = PolyNum([2.4, 1.1])
test_( x >= x ,"""True""")
test_( -x >= x ,"""False""")

print( '#@@@ sqrt','@'*22 )
y05 = PolyNum([0.1,2.5]).sqrt()
y05._strPN_cut = 4;
test_( y05 ,"""PolyNum('(~0.316227766016838~,3.952847075210474~-24.705294220065458~308.816177750818269~...~)')""")#a big difference mpf() with float()!
y1 = y05 * y05 ;#using **0.5 gives better result: PolyNum('(~0.1~,2~0~-1.1234667099445442e-14~0~0~0~...~)')
y1._strPN_cut = 2;
test_( y1 ,"""PolyNum('(~0.1~,2.5~...~)')""")

print( '#@@@ exp','@'*22 )
y1 = PolyNum([0.1,2.]).exp()
y1._strPN_cut = 7;
test_( y1 ,"""PolyNum('(~1.105170918075648~,2.210341836151295~2.210341836151295~1.473561224100864~0.736780612050432~0.294712244820173~0.098237414940058~...~)')""")
y2 = PolyNum([0.1,2.],-2).exp()
y2._strPN_cut = 7;
test_( y2 ,"""PolyNum('(~1~,0.0~0.1~2.0~0.005~0.2~2.000166666666667~...~)')""")

print( '#@@@ expZ','@'*22 )
h = 0.3
pZ = PolyNum('const:(~2~,-4~4~-4~4~...~)') / h ;# 2/h * (~1~-1~)/(~1~1~)
x1 = (flt('-0.7')*pZ + 1).expZ( pZ, flt('0.7'), h ) ;# exp(-0.7 p + 1)
x1._strPN_cut = 7;
test_( x1 ,"""PolyNum('(~1.395612425086089~,1.860816566781453~-0.620272188927151~-0.068919132103017~0.390541748583762~-0.479370852183206~0.432063398542123~...~)*(~1~0~)**(-2)')""")

print( '#@@@ __getitem__','@'*22 )
x = [ 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]
x1 = PolyNum(x)
test_( x1[0] ,"""1""")
x2 = PolyNum(x,-2)
test_( x2[31] ,"""30""")
x3 = PolyNum(x,-3)
test_( (x3[:])[:32] ,"""[0, 0, 0, 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]""")
#x4 = PolyNum(x,4)
## test_( x4[:] ,"""Traceback (most recent call last):""")
# ...
# ValueError: if exponent(=4) is positive, PN slicing is not allowed
#
print( '#@@@ __iter__','@'*22 )
x = [ 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]
x1 = PolyNum(x)
test_( list(x1)[:32] ,"""[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]""")
x2 = PolyNum(x,-2)
test_( list(x2)[:32] ,"""[0, 0, 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]""")
##print( x4 = PolyNum(x,4) ); #& print( list(x4) ); #& Traceback (most recent call last):
## ...
## ValueError: if exponent(=4) is positive, PN __iter__ is not allowed


print( '#@@@ invTr05exp_b0_LaplPN','@'*22 )
##print( Yerr = PolyNum('(~1~2~)') ); #&print( Yerr.invTr05exp_b0_LaplPN(1, 2) ); #& Traceback (most recent call last):
## ...
## ValueError: PN exponent = 1 > 0 - inverese Laplce transform does not exist.
### print( from digitPN import flt ); #&print( Y = PolyNum('(~0~,10~20~30~)') );# #&print( h = flt('0.02') ); #&print( b0 = flt('5') ); #&print( t = [(tk+1)*h for tk in range(len(Y))] );#it sould be any length, but for test ... #&print( y, err = zip( *(Y.invTr05exp_b0_LaplPN(_t, b0) for _t in t) ) ); #&print( def y_ok(t): ); #& ... return flt('10')/sqrt(pi*t)*exp(-b0*b0/t/4)+ \
### flt('20')*erfc(b0/sqrt(t)/2)+ \
### flt('60')*sqrt(t/pi)*exp(-b0*b0/t/4)- \
### flt('30')*b0*erfc(b0/sqrt(t)/2)
### print( yOK = PolyNum([y_ok(t_) for t_ in t]) ); #&print( y = PolyNum(y) ); #&print( abs( y - yOK ) <= (epsilonPNdig*1024*1024) * PolyNum('const:(~1~,2~2~2~2~...~)') ); #& True
###

print( '#@@@ getMantissaExponent_fromStr','@'*22 )
test_( PolyNum('(~1.2~,2.2~-0.3~)*(~1~0~)**(2)') ,"""PolyNum('(~1.2~,2.2~-0.3~)*(~1~0~)**(2)')""")
test_( PolyNum('(~1.2~,2.5~-0.3~)') ,"""PolyNum('(~1.2~,2.5~-0.3~)')""")
test_( PolyNum('(~1.2~,~2.5~-0.3~)') ,"""PolyNum('(~1.2~,2.5~-0.3~)')""")
test_( PolyNum('(~1.2~)') ,"""PolyNum('(~1.2~)')""")
test_( PolyNum('(~0~,2.5~-0.3~)') ,"""PolyNum('(~2.5~,-0.3~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~,2.5~-0.3~)') ,"""PolyNum('(~2.5~,-0.3~)*(~1~0~)**(-1)')""")
test_( PolyNum('(~-1.1~2.2~,-3.3~)') ,"""PolyNum('(~-1.1~,2.2~-3.3~)*(~1~0~)**(1)')""")
test_( PolyNum('') ,"""PolyNum('(~0.0~)')""")
## test_( PolyNum('c(~)') ,"""Traceback (most recent call last):""")
# ...
# ValueError: 'c(~)' error - unknow PN const format.
################################### Mantissa ####################################

print( '#@@@ mantPN_val','@'*22 )

test_( mantPN_val([3.0,0,1,2.1], 5.0) ,"""3.0568""")# 3 * 5**0 + 0 * 5**(-1) + 1 * 5**(-2) + 2 * 5**(-3)
test_( mantPN_val([3,0,1,2], 5) ,"""3.056""")

print( '#@@@ mantPN_mul','@'*22 )

test_( mantPN_mul([1, 2, 3], [9, 5, 1], 3) ,"""[9, 23, 38]""")

test_( mantPN_mul([1, 2, 3], [9., 5, 1], 3) ,"""[9.0, 23.0, 38.0]""")

print( '#@@@ mantPN_inv','@'*22 )
x = [0.5, 7, 0, 0, 0, 0, 0, 0]
y = mantPN_inv(x, 8)
test_( (y[:6]) ,"""[2.0, -28.0, 392.0, -5488.0, 76832.0, -1075648.0]""")
test_( (mantPN_mul(x, y, 8)) ,"""[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]""")
print( '#@@@ mantPN_sqrt','@'*22 )
xx = [0.1,2.,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]
y0 = mantPN_sqrt(xx, 32)
test_( (', '.join([strF(y) for y in y0[:7]])) ,"""'0.316227766, 3.16227766, -15.811388301, 158.113883008, -1976.423537605, 27669.929526473, -415048.9428971'""")# 0.316227766, 3.16227766, -15.8113883, 158.113883, -1976.42354, 27669.9295, -415048.943, 6522197.67
test_( (', '.join([strF(y) for y in mantPN_mul(y0, y0, 32)[:5]])) ,"""'0.1, 2.0, 0.0, 0.0, 0.0'""")# 0.1, 2.0, -9.40395481e-38, -1.88079096e-36, -1.50463277e-35, -5.77778983e-34, -1.00148357e-32, 3.08148791e-32

print( '#@@@ mantPN_power_real','@'*22 )
xx = [0.1,2.,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]
y0 = mantPN_inv(xx, 32)
test_( (y0[:4]) ,"""[10.0, -200.0, 4000.0, -80000.0]""")
y1 = mantPN_power_real(xx, -1, 32)
test_( (y1[:6]) ,"""[10.0, -200.0, 4000.0, -80000.0, 1600000.0, -32000000.0]""")
print('-- 1 ----------')
test_( (mantPN_mul(y0, xx, 32)[:25]) ,"""[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -140737488355328.0, 2251799813685248.0]""")
test_( (mantPN_mul(y1, xx, 32)[:32]) ,"""[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2251799813685248.0, 0.0, 0.0, 18446744073709552000.0, 0.0, 0.0, 0.0, 0.0]""")
y05 = mantPN_power_real(xx, 0.5, 32)
test_( y05[:4] ,"""[0.31622776601683794, 3.162277660168379, -15.811388300841895, 158.11388300841892]""")
test_( mantPN_power_real(y05, 2, 23) ,"""[0.1, 2.0, 0.0, -1.1234667099445442e-14, 0.0, 0.0, 0.0, -7.362751430292565e-10, 0.0, 1.8848643661548967e-7, 0.0, 0.000048252527773565355, 0.0, 0.0, -0.3952847075210474, 6.324555320336758, -101.19288512538813, 0.0, 25905.37859209936, 0.0, 0.0, 0.0, 0.0]""")

print( '#@@@ mantPN_exp','@'*22 )
xx = [0]*32
xx[0:2] = [flt('0.1'),flt('2.')]
y0 = mantPN_exp(xx, 32)
test_( (', '.join([strF(y) for y in y0[:4]])) ,"""'1.105170918, 2.210341836, 2.210341836, 1.473561224'""")
test_( (', '.join([strF(y) for y in mantPN_ln(y0,32)[:4]])) ,"""'0.1, 2.0, 0.0, 0.0'""")

print('OK.')

#@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@##@#
`
return 'python: PNlib_Br tests (see console.log try to force an error in test data)'
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more