ó
ØÆ÷Xc           @` s   d  Z  d d l m Z m Z m Z d g Z d d l m Z d d l m	 Z	 d e
 f d „  ƒ  YZ e d k r} e e ƒ  ƒ n  d S(	   s   
Machine arithmetics - determine the parameters of the
floating-point arithmetic system

Author: Pearu Peterson, September 2003

i    (   t   divisiont   absolute_importt   print_functiont   MachAr(   t   any(   t   errstatec           B` s;   e  Z d  Z e e e d „  d d „ Z d „  Z d „  Z RS(   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, substracted
        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.

    c         C` s   d |  S(   Ns   %24.16e(    (   t   v(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyt   <lambda>d   s    s   Python floating point numberc      
   C` s3   t  d d ƒ  |  j | | | | | ƒ Wd QXd S(   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

        t   undert   ignoreN(   R   t   _do_init(   t   selft
   float_convt   int_convt   float_to_floatt   float_to_strt   title(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyt   __init__b   s    c   .      C` sò  d } d } | d ƒ } | | }	 | | }
 | } xe t  | ƒ D]> } | | } | | } | | } t | | |
 k ƒ r? Pq? q? Wt | | | j f ƒ ‚ | } xg t  | ƒ D]@ } | | } | | } | | | ƒ } t | d k ƒ r­ Pq­ q­ Wt | | | j f ƒ ‚ | } | | ƒ } d } | } xo t  | ƒ D]H } | d } | | } | | } | | } t | | |
 k ƒ r5Pq5q5Wt | | | j f ƒ ‚ | |	 } | } xe t  | ƒ D]> } | | } | | } | | } t | | |
 k ƒ r·Pq·q·Wt | | | j f ƒ ‚ | | } d } t | | |
 k ƒ rAd } n  | | } | | } | d k r€t | | |
 k ƒ r€d } n  | d } | | } | } x t  | ƒ D] } | | } q§W| } x‡ t  | ƒ D]` } | | } t | | |
 k ƒ røPn  | | } | d } | d k  rÎt d t ƒ  ƒ ‚ qÎqÎWt | | | j f ƒ ‚ | } | } | d } | } xe t  | ƒ D]> } | | } t | | |
 k ƒ r Pn  | | } | d } qvWt | | | j f ƒ ‚ | } d } | | } | d k rt | | | |
 k ƒ rd } n  d } d } | } | | }  d }! x» t  | ƒ D]” } | }" |" |" } | | } | |  } t | | |
 k ƒ st t | ƒ |" k ƒ r¡Pn  | | } t | | | k ƒ rÅPn  | d } | | } qEWt | | | j f ƒ ‚ | d	 k r| d }# | | }$ nA d }# | }% x$ | |% k rK|% | }% |# d }# q(W|% |% d }$ xÏ t  | ƒ D]¨ } |" }& |" | }" |" | } |" |  } t | | |
 k ƒ rt t |" ƒ |& k  ƒ r| d } | | } t | | |" k ƒ rt | |" k ƒ rd }! |" }& PqqgPqgWt | | | j f ƒ ‚ | }' |$ | | d k rj| d	 k rj|$ |$ }$ |# d }# n  |$ |' }( | |! } | d k r—|( d }( n  |( |' } | d k rÁ| rÁ|( d }( n  | d
 k rÚ|( d }( n  t | |" k ƒ rù|( d }( n  | | }) t |) | |) k ƒ r*| | | }) n  |) |& | | | }) |( |' d } x7 t  | ƒ D]) }* | d k rz|) |) }) q[|) | }) q[W| |  _ | |  _ | |  _ | | ƒ |  _	 | | ƒ |  _
 | |  _ | | ƒ |  _ | | ƒ |  _ | |  _ |# |  _ |' |  _ | |& ƒ |  _ | |& ƒ |  _ |( |  _ | |) ƒ |  _ | |) ƒ |  _ | |  _ | |  _ |  j |  _ |  j |  _ |  j |  _ d d  l }+ t |+ j | |  j ƒ ƒ ƒ |  _ |	 |	 |	 |	 |	 }, |, |  j }- | |- ƒ |  _ | |- ƒ |  _  d  S(   Ni'  s'   Did not converge after %d tries with %si   i    iÿÿÿÿi   i   sA   could not determine machine tolerance for 'negep', locals() -> %si
   i   (!   t   rangeR   t   RuntimeErrort   dtypet   localst   abst   ibetat   itt   negept   epsnegt   _str_epsnegt   machept   epst   _str_epst   ngrdt   iexpt   minexpt   xmint	   _str_xmint   maxexpt   xmaxt	   _str_xmaxt   irndR   t   epsilont   tinyt   huget   matht   intt   log10t	   precisiont
   resolutiont   _str_resolution(.   R   R   R   R   R   R   t	   max_iterNt   msgt   onet   twot   zerot   at   _t   tempt   temp1t   bt   itempR   t   betaR   t   betahR'   t   tempaR   t   betaint   iR   R   R   R   t   kt   zt   tt   nxrest   yR    t   mxt   izR"   R!   R$   R%   t   jR+   t   tenR/   (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyR
   t   s\   















	

"	







&	



.






.

( 




										"c         C` s   d } | |  j  S(   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   t   fmt(    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyt   __str__G  s    	(   t   __name__t
   __module__t   __doc__t   floatR,   R   R
   RL   (    (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyR      s   O	Ót   __main__N(   RO   t
   __future__R    R   R   t   __all__t   numpy.core.fromnumericR   t   numpy.core.numericR   t   objectR   RM   t   print(    (    (    s0   /tmp/pip-build-X4mzal/numpy/numpy/core/machar.pyt   <module>   s   	ÿ E