python (3.12.0)
Αe d dl mZmZ d dlmZ d dlZd dlZd dlZd dlZd dl Z d dl
Z
d dlZd dlZd dl
Z
d dlZdZ ed Z ed Z ed Zej( j* Zej( j. Zd\ ZZeez d k( Zed
k( rej: d ZneZe
j@ jC e xs e
jD Z#e
j@ jI e#d Z%e
j@ jI e#d Z&d
Z'd Z(d Z)d Z*d Z+d Z,d Z-d dZ. G d d Z/ G d de0 Z1 G d de2 Z3 G d dejh Z5 G d dejh Z6d Z7ed
k( r ejp yy)! )verboserequires_IEEE_754)supportNgh㈵>naninf-inf) 7yACg):@g7yAC__main__zmath_testcases.txtzcmath_testcases.txtc v t j dt j d| d }|dk r|dz }|S )a Convert a non-NaN float x to an integer, in such a way that
adjacent floats are converted to adjacent integers. Then
abs(ulps(x) - ulps(y)) gives the difference in ulps between two
floats.
The results from this function will only make sense on platforms
where native doubles are represented in IEEE 754 binary64 format.
Note: 0.0 and -0.0 are converted to 0 and -1, respectively.
z<qz<dr l )structunpackpack)xns B/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/test/test_math.pyto_ulpsr ( s;
dFKKa01!4A1ugJH c 2 | rdt | | dz
z z S dS )zANumber of '1' bits in binary expansion of a nonnnegative integer. r )count_set_bits)r s r r r N s! ,-1~a!a%i((414r c h || z
dz }|sy|dk( r| S | |z dz }t | | t || z S )zProduct of integers in range(start, stop, 2), computed recursively.
start and stop should both be odd, with start <= stop.
r )partial_product)startstop
numfactorsmids r r r R sL
,1$J qz!Q&uc*_S$-GGGr c dx}}t t | j D ]+ }|t | |dz z dz dz | |z dz dz z }||z }- || t | z
z S )zFactorial of nonnegative integer n, via "Binary Split Factorial Formula"
described at http://www.luschny.de/math/factorial/binarysplitfact.html
r )reversedrange
bit_lengthr r )r innerouteris r py_factorialr$ ` s}
EE
eALLN+
,
!q1u*!1A!5Q!|a7GHH
Q**++r c t t | t | z
}t | |z
}||k s||k ryd}|j |||| S )zGiven finite floats `expected` and `got`, check that they're
approximately equal to within the given number of ulps or the
given absolute tolerance, whichever is bigger.
Returns None on success and an error message on failure.
NzAerror = {:.3g} ({:d} ulps); permitted error = {:.3g} or {:d} ulps)absr format)expectedgotulp_tolabs_tol ulp_error abs_errorfmts r
ulp_abs_checkr/ k sZ GH%45IHsN#I GyG37zz)YAAr c # l K t | d 5 }|D ] }d|v r|d|j d }|j s,|j d \ }}|j \ }}}|j }|d } |dd }
||t | t | |
f ddd y# 1 sw Y yxY ww)zParse a file with test values
-- starts a comment
blank lines, or lines containing only a comment, are ignored
other lines are expected to have the form
id fn arg -> expected [flag]*
utf-8encoding--N->r r )openindexstripsplitfloat)fnamefplinelhsrhsidfnarg
rhs_piecesexpflagss r parse_mtestfilerF } s
eg &