
    Dg--                         d Z dgZddlmZ ddlmZ ddlmZ  G 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                   2    e Zd ZdZeeed dfdZd Z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                     d| z  S )Nz%24.16e )vs    G/var/www/sysmax/venv/lib/python3.11/site-packages/numpy/core/_machar.py<lambda>zMachAr.<lambda>j   s
    y1}     zPython floating point numberc                     t          d          5  |                     |||||           ddd           dS # 1 swxY 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titles         r   __init__zMachAr.__init__h   s     H%%% 	U 	UMM*heTTT	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us   8<<c                    d}d} |d          }||z   }	||z
  }
|}t          |          D ])}||z   }||z   }||z
  }t          ||z
  |
k              r n*t          |||j        fz            |}t          |          D ]/}||z   }||z   } |||z
            }t          |dk              r n0t          |||j        fz            |} ||          }d}|}t          |          D ].}|dz   }||z  }||z   }||z
  }t          ||z
  |
k              r n/t          |||j        fz            ||	z  }|}t          |          D ])}||z   }||z   }||z
  }t          ||z
  |
k              r n*t          |||j        fz            ||z   }d}t          ||z
  |
k              rd}||z   }||z   }|dk    rt          ||z
  |
k              rd}|dz   }||z  }|}t          |          D ]}||z  }|}t          |          D ]M}||z
  }t          ||z
  |
k              r nH||z  }|dz
  }|dk     rt          dt	                      z            Nt          |||j        fz            | }|}| dz
  }|}t          |          D ])}||z   }t          ||z
  |
k              r n$||z  }|dz   }*t          |||j        fz            |}d}||z   }|dk    rt          ||z  |z
  |
k              rd}d}d}|}||z   } d}!t          |          D ]r}|}"|"|"z  }||z  }|| z  }t          ||z   |
k              s t          t          |          |"k              r nA||z  }t          ||z  |k              r n$|dz   }||z   }st          |||j        fz            |d	k    r|dz   }#||z   }$n"d}#|}%||%k    r|%|z  }%|#dz   }#||%k    |%|%z   dz
  }$t          |          D ]}|"}&|"|z  }"|"|z  }|"| z  }t          ||z   |
k              rZt          t          |"          |&k               r:|dz   }||z  }t          ||z  |"k              rt          ||"k              rd}!|"}& n nt          |||j        fz            | }'|$||z   dz
  k    r|d	k    r
|$|$z   }$|#dz   }#|$|'z   }(||!z   }|dk    r|(dz
  }(|(|'z   }|dk    r|s|(dz
  }(|d
k    r|(dz
  }(t          ||"k              r|(dz
  }(||z
  })t          |)|z  |)k              r|||z  z
  })|)|&|z  |z  |z  z  })|(|'z   dz   }t          |          D ]}*|dk    r|)|)z   })|)|z  })t          |&||z  z            }+|| _        || _        || _         ||          | _	         ||          | _
        || _         ||          | _         ||          | _        || _        |#| _        |'| _         ||&          | _         ||&          | _        |(| _         ||)          | _         ||)          | _        || _        || _        | j        | _        | j        | _        | j        | _        | j        | _         || j                  | _         ||+          | _         ||+          | _        dd l},tA          |,!                     || j                                       | _"        |	|	z   |	z   |	z   |	z   }-|-| j"         z  }. ||.          | _#         ||.          | _$        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&   betahr5   tempar'   betainir(   r*   r+   r-   kztnxresyr.   mxizr0   r/   r2   r3   jr;   r=   tenrA   s/                                                  r   r   zMachAr._do_initz   s6	   	7jmmCiSy y!! 	5 	5AAAs7D1HE53;$&''  sa^3444y!! 	5 	5AAAq5DHT!V$$E5A:  sa^3444z%   y!! 	5 	5AaBDAs7D1HE53;$&''  sa^3444s
y!! 	5 	5AAAs7D1HE53;$&''  sa^34445ytAv~ 	DDu}199T%Z4/009D Qtu 	 	AF
AAy!! 	5 	5A7D48t#$$ DAAIEqyy" $ADJHH$N O O O  sa^3444 y!! 	5 	5A7D48t#$$ DAaZFFsa^3444 Sy199T#X^t3449D #Iy!! 	5 	5AA!A#AQ3D1Q3$; 3s1vv{#3#3 6ME5:?## AAAAAsa^3444B;;q5DQBBDBr''%Zax r'' b1B y!! 	5 	5ADF
ACAq5DAEd?## CFFTM(:(: EvuTzQ'' C	NN EDEsa^3444 Q??u{{bB!8Dfe|199aZFVOA::a:aZFr66aZFqAv;; 	 aZFV|tCx4   	%f$DtDy~d*+VOaq 	# 	#Azzd{d{ !455

$nV,,'<//!>#&&$S))		"N4((	%d++"N4((	%d++	
xI	I	#y$0L$;$;!"0.1C"D"D'3|4F'G'G$djj)A)ABBBCCCi#o#c)dn_-
(.44+|J77r   c                     d}|| j         z  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   fmts     r   __str__zMachAr.__str__S  s    	U 	 T]""r   N)	__name__
__module____qualname____doc__floatr>   r   r   r_   r
   r   r   r   r      sn        T Tl #( %445U U U U$W8 W8 W8r# # # # #r   __main__N)rc   __all__fromnumericr   _ufunc_configr   _utilsr   r   r`   printr
   r   r   <module>rk      s     *       # # # # # #      
O# O# O# O# O# O# O# O#d
 z	E&&((OOOOO r   