Check floats precision.
Syntax :
precm(b) for the mantissa precision where b is the base.
prece(b) for the exponent precision where b is the base.
Examples :
precm(2) for the maximum number of bits used for the mantissa
precm(10) for the maximum number of significative digits used for the mantissa
prece() for the minimum and maximum values for the exponent.
from math import tan def precm(b): k,b=0,float(b) while 1+b**-k-1>0: k+=1 return k def prece(): a=-1 while 2.**a>0: a*=2 while 2.**a==0: a+=1 b=1 while str(2.**b)[0:3]!='inf': b*=2 while str(2.**b)[0:3]=='inf': b-=1 return [a,b] def precm2(b): n = 0 dold = 0 while 1: d = tan(355/226 + b**-n) - tan(355/226) if d == dold or d < 0: break dold = d n += 1 return n