Ë
    /æj--  ã                   ól   — 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«       «       y	y	)
z€
Machine arithmetic - determine the parameters of the
floating-point arithmetic system

Author: Pearu Peterson, September 2003

ÚMachAré   )Úany)Úerrstateé   )Ú
set_modulec                   ó0   — e Zd ZdZeeed„ dfd„Zd„ Zd„ Zy)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    úU/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/numpy/core/_machar.pyú<lambda>zMachAr.<lambda>j   s
   €  y°1¡}€ ó    zPython floating point numberc                 óp   — t        d¬«      5  | j                  |||||«       ddd«       y# 1 sw Y   yxY w)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   s9   € ô ˜HÔ%ñ 	UØ�M‰M˜* h°ÀÈeÔT÷	U÷ 	Uñ 	Uús   �,¬5c                 ó²  — d}d} |d«      }||z   }	||z
  }
|}t        |«      D ]$  }||z   }||z   }||z
  }t        ||z
  |
k7  «      sŒ$ n t        ||j                  fz  «      ‚|}t        |«      D ]'  }||z   }||z   } |||z
  «      }t        |dk7  «      sŒ' n t        |||j                  fz  «      ‚|} ||«      }d}|}t        |«      D ])  }|dz   }||z  }||z   }||z
  }t        ||z
  |
k7  «      sŒ) n t        |||j                  fz  «      ‚||	z  }|}t        |«      D ]$  }||z   }||z   }||z
  }t        ||z
  |
k7  «      sŒ$ n t        |||j                  fz  «      ‚||z   }d}t        ||z
  |
k7  «      rd}||z   }||z   }|dk(  rt        ||z
  |
k7  «      rd}|dz   }||z  }|}t        |«      D ]  }||z  }Œ	 |}t        |«      D ]?  }||z
  }t        ||z
  |
k7  «      r nA||z  }|dz
  }|dk  sŒ+t        dt	        «       z  «      ‚ t        |||j                  fz  «      ‚| }|}| dz
  }|}t        |«      D ]$  }||z   }t        ||z
  |
k7  «      r n&||z  }|dz   }Œ& t        |||j                  fz  «      ‚|}d}||z   }|dk(  rt        ||z  |z
  |
k7  «      rd}d}d}|}||z   } d}!t        |«      D ]_  }|}"|"|"z  }||z  }|| z  }t        ||z   |
k(  «      st        t        |«      |"k\  «      r n>||z  }t        ||z  |k(  «      r n&|dz   }||z   }Œa t        |||j                  fz  «      ‚|d	k7  r|dz   }#||z   }$n!d}#|}%||%k\  r|%|z  }%|#dz   }#||%k\  rŒ|%|%z   dz
  }$t        |«      D ]m  }|"}&|"|z  }"|"|z  }|"| z  }t        ||z   |
k7  «      rHt        t        |"«      |&k  «      r1|dz   }||z  }t        ||z  |"k(  «      sŒXt        ||"k7  «      sŒgd}!|"}& n n t        |||j                  fz  «      ‚| }'|$||z   dz
  k  r|d	k7  r
|$|$z   }$|#dz   }#|$|'z   }(||!z   }|dk\  r|(dz
  }(|(|'z   }|dk(  r|s|(dz
  }(|d
kD  r|(dz
  }(t        ||"k7  «      r|(dz
  }(||z
  })t        |)|z  |)k7  «      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        |,jC                   || j                  «      «       «      | _"        |	|	z   |	z   |	z   |	z   }-|-| jD                   z  }. ||.«      | _#         ||.«      | _$        y )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   sØ  € Øˆ	Ø7ˆÙ˜‹mˆØ�C‰iˆØ�S‰yˆð ˆÜ�yÓ!ò 	5ˆAØ�A‘ˆAØ�s‘7ˆDØ˜1‘HˆEÜ�5˜3‘; $Ñ&Õ'Ùð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4ØˆÜ�yÓ!ò 	5ˆAØ�A‘ˆAØ�q‘5ˆDÙ˜T !™VÓ$ˆEÜ�5˜A‘:�Ùð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4ØˆÙ˜%Ó ˆð ˆØˆÜ�yÓ!ò 	5ˆAØ�a‘ˆBØ�D‘ˆAØ�s‘7ˆDØ˜1‘HˆEÜ�5˜3‘; $Ñ&Õ'Ùð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4à�s‘
ˆØˆÜ�yÓ!ò 	5ˆAØ�A‘ˆAØ�s‘7ˆDØ˜1‘HˆEÜ�5˜3‘; $Ñ&Õ'Ùð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4Ø�5‰yˆØˆÜˆt�A‰v˜‰~ÔØˆDØ�D‘ˆØ�u‰}ˆØ�1Š9œ˜T %™Z¨4Ñ/Ô0ØˆDð �Q‘ˆØ�t‘ˆØˆÜ�u“ò 	ˆAØ�F‘
‰Að	àˆÜ�yÓ!ò 	5ˆAØ˜‘7ˆDÜ�4˜‘8˜tÑ#Ô$ÙØ�D‘ˆAØ˜A‘IˆEà�q‹yÜ"ð $AÜDJÃHñ$Nó Oð Oð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4Ø�ˆØˆð �˜‘ˆØˆä�yÓ!ò 	5ˆAØ˜‘7ˆDÜ�4˜‘8˜tÑ#Ô$ÙØ�D‘ˆAØ˜a‘Z‰Fð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4Øˆð ˆØ�S‰yˆØ�1Š9œ˜T #™X¨™^¨tÑ3Ô4ØˆDð ˆØˆØˆØ�#‰IˆØˆÜ�yÓ!ò 	5ˆAØˆAØ�!‘ˆAØ�#‘ˆAØ�Q‘3ˆDÜ�1�Q‘3˜$‘;Ô¤3¤s¨1£v°¡{Ô#3ÙØ˜6‘MˆEÜ�5˜‘: ‘?Ô#ÙØ�A‘ˆAØ�A‘‰Að	5ô ˜s a¨¯© ^Ñ3Ó4Ð4Ø�BŠ;Ø�q‘5ˆDØ�Q‘‰BàˆDØˆBØ�r’'Ø˜%‘Z�Ø˜a‘x�ð �r“'ð �b‘˜1‘ˆBô �yÓ!ò 	5ˆAØˆDØ�F‘
ˆAØ�C‘ˆAØ�q‘5ˆDÜ�A˜‘E˜d‘?Ô#¬¬C°«F°T©MÔ(:Ø˜‘E�Ø˜v™�Ü�u˜T‘z Q‘Õ'¬C°¸±	­NØ�EØ�DÙáð	5ô ˜s a¨¯© ^Ñ3Ó4Ð4Ø�ˆð ��Q‘˜‘Š?˜u¨š{Ø�b‘ˆBØ˜!‘8ˆDØ�f‘ˆØ�e‰|ˆØ�1Š9Ø˜a‘ZˆFØ�V‰OˆØ�AŠ:™aØ˜a‘ZˆFØˆrŠ6Ø˜a‘ZˆFÜˆq�A‰vŒ;Ø˜a‘ZˆFØ�V‰|ˆÜˆt�C‰x˜4ÑÔ Ø˜˜f™Ñ$ˆDØ�t˜D‘y ‘~ dÑ*Ñ+ˆØ�V‰O˜aÑˆÜ�q“ò 	#ˆAØ˜ŠzØ˜d‘{‘à˜d‘{‘ð		#ô ! ¨°©Ñ!4Ó5ÐàˆŒ
ØˆŒØˆŒ
Ù$ VÓ,ˆŒÙ'¨Ó/ˆÔØˆŒÙ! #Ó&ˆŒÙ$ SÓ)ˆŒØˆŒ	ØˆŒ	ØˆŒÙ" 4Ó(ˆŒ	Ù% dÓ+ˆŒØˆŒÙ" 4Ó(ˆŒ	Ù% dÓ+ˆŒØˆŒ	àˆŒ
à—x‘xˆŒØ—I‘IˆŒ	Ø—I‘IˆŒ	Ø#Ÿy™yˆÔÙ$0°·±Ó$;ˆÔ!Ù"0Ð1CÓ"DˆÔÙ'3Ð4FÓ'GˆÔ$ãÜ˜dŸj™j©¸¿¹Ó)AÓBÐBÓCˆŒØ�C‰i˜#‰o Ñ# cÑ)ˆØ˜dŸn™n˜_Ñ-ˆ
Ù(¨Ó4ˆŒÙ+¨JÓ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      s+   „ ñTðl #(°Ø %Ù4Ø5óUò$W8ór#r   Ú__main__N)rc   Ú__all__Úfromnumericr   Ú_ufunc_configr   Ú_utilsr   r   r`   Úprintr
   r   r   ú<module>rk      sA   ðñð ˆ*€å Ý #Ý ÷
O#ñ O#ðd
 ˆzÒÙ	‰&‹(…Oð r   