U
    bb-                     @   sZ   d Z dgZddlmZ ddlmZ ddlmZ edG dd dZe	dkrVe
e  d	S )
z
Machine arithmetic - determine the parameters of the
floating-point arithmetic system

Author: Pearu Peterson, September 2003

MachAr    )any)errstate)
set_moduleZnumpyc                   @   s8   e Zd ZdZeeedd dfddZdd Zd	d
 ZdS )r   aw  
    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] positive floating point number with full precision).
    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
        An alias for `smallest_normal`, kept for backwards compatibility.
    huge : float
        Same as `xmax`.
    precision : float
        ``- int(-log10(eps))``
    resolution : float
        ``- 10**(-precision)``
    smallest_normal : float
        The smallest positive floating point number with 1 as leading bit in
        the mantissa following IEEE-754. Same as `xmin`.
    smallest_subnormal : float
        The smallest positive floating point number with 0 as leading bit in
        the mantissa following IEEE-754.

    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 )Nz%24.16e )vr   r   R/home/fireinfo/NEWAFireInfo/venv/lib/python3.8/site-packages/numpy/core/_machar.py<lambda>k       zMachAr.<lambda>zPython floating point numberc              	   C   s,   t dd | ||||| W 5 Q R X dS )a!  

        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

        ignore)ZunderN)r   _do_init)self
float_convint_convfloat_to_floatfloat_to_strtitler   r   r   __init__i   s    zMachAr.__init__c           /      C   s  d}d}|d}|| }	|| }
|}t |D ]0}|| }|| }|| }t|| |
kr, qpq,t|||jf |}t |D ]0}|| }|| }||| }t|dkr| qq|t|||jf |}||}d}|}t |D ]:}|d }|| }|| }|| }t|| |
kr q*qt|||jf ||	 }|}t |D ]6}|| }|| }|| }t|| |
kr> qq>t|||jf || }d}t|| |
krd}|| }|| }|dkrt|| |
krd}|d }|| }|}t |D ]}|| }q|}t |D ]N}|| }t|| |
kr6 qt|| }|d }|dk rtdt  qt|||jf | }|}| d }|}t |D ]6}|| }t|| |
kr q|| }|d }qt|||jf |}d}|| }|dkrt|| | |
krd}d}d}|}|| } d}!t |D ]|}|}"|"|" }|| }||  }t|| |
ksvtt||"kr| q|| }t|| |kr q|d }|| }q2t|||jf |d	kr|d }#|| }$n2d}#|}%||%kr|%| }%|#d }#q|%|% d }$t |D ]}|"}&|"| }"|"| }|"|  }t|| |
krtt|"|&k r|d }|| }t|| |"krt||"krd}!|"}& qn qqt|||jf | }'|$|| d kr|d	kr|$|$ }$|#d }#|$|' }(||! }|dkr|(d }(|(|' }|dkr,|s,|(d }(|d
kr>|(d }(t||"krT|(d }(|| })t|)| |)krz|||  })|)|&| | |  })|(|' d }t |D ]"}*|dkr|)|) })n|)| })qt|&||  }+|| _|| _|| _||| _	||| _
|| _||| _||| _|| _|#| _|'| _||&| _||&| _|(| _||)| _||)| _|| _|| _| j| _| j| _| j| _| j| _|| j| _||+| _||+| _dd l},t |,!|| j | _"|	|	 |	 |	 |	 }-|-| j"  }.||.| _#||.| _$d S )Ni'  z'Did not converge after %d tries with %s   r         zAcould not determine machine tolerance for 'negep', locals() -> %s
      )%ranger   RuntimeErrorZdtypelocalsabsibetaitnegepepsnegZ_str_epsnegmachepepsZ_str_epsngrdiexpminexpxminZ	_str_xminmaxexpxmaxZ	_str_xmaxirndr   epsilonZtinyZhugeZsmallest_normalZ_str_smallest_normalsmallest_subnormalZ_str_smallest_subnormalmathintlog10Z	precision
resolutionZ_str_resolution)/r   r   r   r   r   r   Z	max_iterNmsgZoneZtwoZzeroa_tempZtemp1bZitempr   betar   Zbetahr*   Ztempar    Zbetainir!   r"   r#   r$   kztZnxresyr%   ZmxZizr'   r&   r(   r)   jr,   r-   Ztenr0   r   r   r   r   {   sh   



 $


$ 















zMachAr._do_initc                 C   s   d}|| j  S )NaC  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)
smallest_normal=%(smallest_normal)s    smallest_subnormal=%(smallest_subnormal)s
---------------------------------------------------------------------
)__dict__)r   fmtr   r   r   __str__T  s    zMachAr.__str__N)	__name__
__module____qualname____doc__floatr.   r   r   r?   r   r   r   r   r      s   V
 Z__main__N)rC   __all__Znumpy.core.fromnumericr   Znumpy.core._ufunc_configr   Znumpy.core.overridesr   r   r@   printr   r   r   r   <module>   s     T