o
    :‘ði--  ã                   @   sV   d Z dgZddlmZ ddlmZ ddlmZ G dd„ dƒZe	dkr)e
eƒ ƒ d	S d	S )
z€
Machine arithmetic - determine the parameters of the
floating-point arithmetic system

Author: Pearu Peterson, September 2003

ÚMachAré   )Úany)Úerrstateé   )Ú
set_modulec                   @   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/root/parts/websockify/install/lib/python3.10/site-packages/numpy/_core/_machar.pyÚ<lambda>j   s    zMachAr.<lambda>zPython floating point numberc                 C   sB   t dd�� |  |||||¡ W d  ƒ dS 1 sw   Y  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)ÚunderN)r   Ú_do_init)ÚselfÚ
float_convÚint_convÚfloat_to_floatÚfloat_to_strÚtitler   r   r	   Ú__init__h   s   "ÿzMachAr.__init__c           /      C   sä  d}d}|dƒ}|| }	|| }
|}t |ƒD ]}|| }|| }|| }t|| |
kƒr. n
qt|||jf ƒ‚|}t |ƒD ]}|| }|| }||| ƒ}t|dkƒrV n
q>t|||jf ƒ‚|}||ƒ}d}|}t |ƒD ]}|d }|| }|| }|| }t|| |
kƒrŠ n
qnt|||jf ƒ‚||	 }|}t |ƒD ]}|| }|| }|| }t|| |
kƒr¶ n
qžt|||jf ƒ‚|| }d}t|| |
kƒrÐd}|| }|| }|dkræt|| |
kƒræd}|d }|| }|}t |ƒD ]}|| }qô|}t |ƒD ]&}|| }t|| |
kƒ�r n|| }|d }|dk �r&tdtƒ  ƒ‚�qt|||jf ƒ‚| }|}| d }|}t |ƒD ]}|| }t|| |
kƒ�rR n|| }|d }�qAt|||jf ƒ‚|}d}|| }|dk�rt|| | |
kƒ�rd}d}d}|}|| } d}!t |ƒD ]<}|}"|"|" }|| }||  }t|| |
kƒ�s±tt|ƒ|"kƒ�r³ n"|| }t|| |kƒ�rÂ n|d }|| }�q�t|||jf ƒ‚|d	k�rã|d }#|| }$nd}#|}%||%k�rù|%| }%|#d }#||%k�sì|%|% d }$t |ƒD ]C}|"}&|"| }"|"| }|"|  }t|| |
kƒ�rEtt|"ƒ|&k ƒ�rE|d }|| }t|| |"kƒ�rCt||"kƒ�rCd}!|"}& n�q n	t|||jf ƒ‚| }'|$|| d k�ri|d	k�ri|$|$ }$|#d }#|$|' }(||! }|dk�rz|(d }(|(|' }|dk�rŠ|�sŠ|(d }(|d
k�r“|(d }(t||"kƒ�rž|(d }(|| })t|)| |)kƒ�r±|||  })|)|&| | |  })|(|' d }t |ƒD ]}*|dk�rÒ|)|) })�qÅ|)| })�qÅt|&||  ƒ}+|| _|| _|| _||ƒ| _	||ƒ| _
|| _||ƒ| _||ƒ| _|| _|#| _|'| _||&ƒ| _||&ƒ| _|(| _||)ƒ| _||)ƒ| _|| _|| _| j| _| j| _| j| _| j| _|| jƒ| _||+ƒ| _||+ƒ| _dd l},t |, !|| jƒ¡ ƒ| _"|	|	 |	 |	 |	 }-|-| j"  }.||.ƒ| _#||.ƒ| _$d S )Ni'  z'Did not converge after %d tries with %sr   é    éÿÿÿÿr   é   zAcould not determine machine tolerance for 'negep', locals() -> %sé
   é   )%Úranger   ÚRuntimeErrorÚdtypeÚlocalsÚabsÚibetaÚitÚnegepÚepsnegÚ_str_epsnegÚmachepÚepsÚ_str_epsÚngrdÚiexpÚminexpÚxminÚ	_str_xminÚmaxexpÚxmaxÚ	_str_xmaxÚirndr   ÚepsilonÚtinyÚhugeÚsmallest_normalÚ_str_smallest_normalÚsmallest_subnormalÚ_str_smallest_subnormalÚmathÚintÚlog10Ú	precisionÚ
resolutionÚ_str_resolution)/r   r   r   r   r   r   Ú	max_iterNÚmsgÚoneÚtwoÚzeroÚaÚ_ÚtempÚtemp1ÚbÚitempr   Úbetar    Úbetahr/   Útempar!   ÚbetainÚir"   r$   r%   r'   ÚkÚzÚtÚnxresÚyr(   ÚmxÚizr*   r)   r,   r-   Újr5   r7   Útenr;   r   r   r	   r   z   sv  ÿÿÿÿ

ÿÿ
 $



þ$ €













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__S  s   ÿ
zMachAr.__str__N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfloatr8   r   r   rX   r   r   r   r	   r      s    V
ý ZÚ__main__N)r\   Ú__all__Úfromnumericr   Ú_ufunc_configr   Ú_utilsr   r   rY   Úprintr   r   r   r	   Ú<module>   s      Tÿ