ó 2ÄÈ[c@`sdZddlmZmZmZdgZddlmZddlm Z de fd„ƒYZ e dkr}e e ƒƒndS( s Machine arithmetics - determine the parameters of the floating-point arithmetic system Author: Pearu Peterson, September 2003 i(tdivisiontabsolute_importtprint_functiontMachAr(tany(terrstatecB`s;eZdZeeed„dd„Zd„Zd„ZRS(sñ Diagnosing machine parameters. Attributes ---------- ibeta : int Radix in which numbers are represented. it : int Number of base-`ibeta` digits in the floating point mantissa M. machep : int Exponent of the smallest (most negative) power of `ibeta` that, added to 1.0, gives something different from 1.0 eps : float Floating-point number ``beta**machep`` (floating point precision) negep : int Exponent of the smallest power of `ibeta` that, subtracted from 1.0, gives something different from 1.0. epsneg : float Floating-point number ``beta**negep``. iexp : int Number of bits in the exponent (including its sign and bias). minexp : int Smallest (most negative) power of `ibeta` consistent with there being no leading zeros in the mantissa. xmin : float Floating point number ``beta**minexp`` (the smallest [in magnitude] usable floating value). maxexp : int Smallest (positive) power of `ibeta` that causes overflow. xmax : float ``(1-epsneg) * beta**maxexp`` (the largest [in magnitude] usable floating value). irnd : int In ``range(6)``, information on what kind of rounding is done in addition, and on how underflow is handled. ngrd : int Number of 'guard digits' used when truncating the product of two mantissas to fit the representation. epsilon : float Same as `eps`. tiny : float Same as `xmin`. huge : float Same as `xmax`. precision : float ``- int(-log10(eps))`` resolution : float ``- 10**(-precision)`` Parameters ---------- float_conv : function, optional Function that converts an integer or integer array to a float or float array. Default is `float`. int_conv : function, optional Function that converts a float or float array to an integer or integer array. Default is `int`. float_to_float : function, optional Function that converts a float array to float. Default is `float`. Note that this does not seem to do anything useful in the current implementation. float_to_str : function, optional Function that converts a single float to a string. Default is ``lambda v:'%24.16e' %v``. title : str, optional Title that is printed in the string representation of `MachAr`. See Also -------- finfo : Machine limits for floating point types. iinfo : Machine limits for integer types. References ---------- .. [1] Press, Teukolsky, Vetterling and Flannery, "Numerical Recipes in C++," 2nd ed, Cambridge University Press, 2002, p. 31. cC`sd|S(Ns%24.16e((tv((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pytdssPython floating point numberc C`s3tddƒ|j|||||ƒWdQXdS(s! float_conv - convert integer to float (array) int_conv - convert float (array) to integer float_to_float - convert float array to float float_to_str - convert array float to str title - description of used floating point numbers tundertignoreN(Rt_do_init(tselft float_convtint_convtfloat_to_floatt float_to_strttitle((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pyt__init__bsc.C`sòd}d}|dƒ}||} ||} |} xet|ƒD]>} | | } | |} | | }t||| kƒr?Pq?q?Wt|| |jfƒ‚|}xgt|ƒD]@} ||}| |} || | ƒ}t|dkƒr­Pq­q­Wt|| |jfƒ‚|}||ƒ}d}|}xot|ƒD]H} |d}||}||} | |}t||| kƒr5Pq5q5Wt|| |jfƒ‚|| }|} xet|ƒD]>} | | } | |} | | }t||| kƒr·Pq·q·Wt|| |jfƒ‚| |} d}t| | | kƒrAd}n| |}||} |dkr€t| || kƒr€d}n|d}||}|} xt|ƒD]}| |} q§W| }x‡t|ƒD]`} || } t| || kƒrøPn| |} |d}|dkrÎtdtƒƒ‚qÎqÎWt|| |jfƒ‚| }| }| d}|} xet|ƒD]>} || } t| || kƒr Pn| |} |d}qvWt|| |jfƒ‚| }d}||} |dkrt| ||| kƒrd}nd}d}|}||} d}!x»t|ƒD]”} |}"|"|"}||} || } t| | | kƒstt|ƒ|"kƒr¡Pn| |}t|||kƒrÅPn|d}||}qEWt|| |jfƒ‚|d kr|d}#||}$nAd}#|}%x$||%krK|%|}%|#d}#q(W|%|%d}$xÏt|ƒD]¨} |"}&|"|}"|"|} |"| } t| | | kƒrtt|"ƒ|&kƒr|d}| |}t|||"kƒrt| |"kƒrd}!|"}&PqqgPqgWt|| |jfƒ‚| }'|$||dkrj|d krj|$|$}$|#d}#n|$|'}(||!}|dkr—|(d}(n|(|'}|dkrÁ| rÁ|(d}(n|d krÚ|(d}(nt| |"kƒrù|(d}(n||})t|)||)kƒr*|||})n|)|&|||})|(|'d}x7t|ƒD])}*|dkrz|)|)})q[|)|})q[W||_||_||_||ƒ|_ ||ƒ|_ ||_ ||ƒ|_ ||ƒ|_ ||_|#|_|'|_||&ƒ|_||&ƒ|_|(|_||)ƒ|_||)ƒ|_||_||_|j |_|j|_|j|_ddl}+t|+j||j ƒƒ ƒ|_| | | | | },|,|j }-||-ƒ|_||-ƒ|_ dS( Ni's'Did not converge after %d tries with %siiiÿÿÿÿiisAcould not determine machine tolerance for 'negep', locals() -> %si i(!trangeRt RuntimeErrortdtypetlocalstabstibetatittnegeptepsnegt _str_epsnegtmacheptepst_str_epstngrdtiexptminexptxmint _str_xmintmaxexptxmaxt _str_xmaxtirndRtepsilonttinythugetmathtinttlog10t precisiont resolutiont_str_resolution(.R R R RRRt max_iterNtmsgtonettwotzerotat_ttempttemp1tbtitempRtbetaRtbetahR'ttempaRtbetaintiRRRRtktztttnxrestyR tmxtizR"R!R$R%tjR+ttenR/((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pyR ts\                     "           &     .         .  (                             "cC`sd}||jS(NsòMachine parameters for %(title)s --------------------------------------------------------------------- ibeta=%(ibeta)s it=%(it)s iexp=%(iexp)s ngrd=%(ngrd)s irnd=%(irnd)s machep=%(machep)s eps=%(_str_eps)s (beta**machep == epsilon) negep =%(negep)s epsneg=%(_str_epsneg)s (beta**epsneg) minexp=%(minexp)s xmin=%(_str_xmin)s (beta**minexp == tiny) maxexp=%(maxexp)s xmax=%(_str_xmax)s ((1-epsneg)*beta**maxexp == huge) --------------------------------------------------------------------- (t__dict__(R tfmt((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pyt__str__Gs (t__name__t __module__t__doc__tfloatR,RR RL(((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pyRsO  Ót__main__N(ROt __future__RRRt__all__tnumpy.core.fromnumericRtnumpy.core.numericRtobjectRRMtprint(((s0/tmp/pip-build-fiC0ax/numpy/numpy/core/machar.pyts ÿE