Sindbad~EG File Manager
�
'Μg+� � � � 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"d�Z. G d� d� Z/ G d� de0� Z1 G d� de2� Z3 G d� d� Z4 G d� dejj � Z6 G d� d ejj � Z7d!� Z8ed
k( r ejr � yy)#� )�verbose�requires_IEEE_754)�supportNg�h㈵��>�nan�inf�-inf)� ��7y�ACg�):��@g��7y�AC�__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 )�struct�unpack�pack)�x�ns �+/usr/local/lib/python3.12/test/test_math.py�to_ulpsr ( s; � � �
�
�d�F�K�K��a�0�1�!�4�A��1�u���g�J���H� 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�(�(�4�1�4r c �h � || z
dz }|sy|dk( r| S | |z dz }t | |� t ||� z S )z�Product of integers in range(start, stop, 2), computed recursively.
start and stop should both be odd, with start <= stop.
r )�partial_product)�start�stop�
numfactors�mids r r r R sL � �
��,�1�$�J��� �q�����z�!�Q�&���u�c�*�_�S�$�-G�G�Gr c �� � dx}}t t | j � � � D ]+ }|t | |dz z dz dz | |z dz dz � z }||z }�- || t | � z
z S )z�Factorial of nonnegative integer n, via "Binary Split Factorial Formula"
described at http://www.luschny.de/math/factorial/binarysplitfact.html
r )�reversed�range�
bit_lengthr r )r �inner�outer�is r �py_factorialr$ ` sx � �
��E�E�
�e�A�L�L�N�+�
,��
��!�q�1�u�*��!1�A�!5��Q��!�|�a�7G�H�H��
���� -� �Q���*�*�+�+r c � � t t | � t |� z
� }t | |z
� }||k s||k ryd}|j ||||� S )z�Given 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)�expected�got�ulp_tol�abs_tol� ulp_error� abs_error�fmts r �
ulp_abs_checkr/ k sZ � � �G�H�%����4�5�I��H�s�N�#�I� �G��y�G�3��7���z�z�)�Y���A�Ar 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 w�w)z�Parse 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-8��encoding�--N�->r r )�open�index�strip�split�float)�fname�fp�line�lhs�rhs�id�fn�arg�
rhs_pieces�exp�flagss r �parse_mtestfilerF } s� � �� �
�e�g� &�"��D��t�|��-�T�Z�Z��-�.���:�:�<���z�z�$�'�H�C���)�)�+�K�B��C�����J��Q�-�C��q�r�N�E��r�5��:�u�S�z�5�9�9� �
'� &� &�s �B4�BB(� B4�(B1�-B4c
# � K � t | d�� 5 }|D ]� }|j d� s|j � s�%|j d� \ }}|j � \ }}}}|j � } | d | d }}
| dd }||t |� t |� t |
� t |� |f�� �� ddd� y# 1 sw Y yxY w�w) z�Parse a file with test values
Empty lines or lines starting with -- are ignored
yields id, fn, arg_real, arg_imag, exp_real, exp_imag
r1 r2 r4 r5 r r � N)r6 �
startswithr8 r9 r: )
r; r<