File: //usr/local/lib/python3.7/test/__pycache__/test_math.cpython-37.pyc
B
��g�� � @ sp d dl mZmZmZ d dlmZ d dlZd dlZd dlZd dl Z d dl
Z
d dlZd dlZdZ
ed�Zed�Zed�ZejjZd\ZZee d kZed
kr�ejd ZneZej�e�p�ejZej� ed�Z!ej� ed�Z"d
d� Z#dd� Z$dd� Z%dd� Z&dd� Z'dd� Z(dd� Z)dd� Z*d)dd �Z+G d!d"� d"e,�Z-G d#d$� d$ej.�Z/G d%d&� d&ej.�Z0d'd(� Z1ed
k�rle1� dS )*� )�run_unittest�verbose�requires_IEEE_754)�supportNg�h㈵��>�nan�infz-inf)g ��7y�ACg�):��@g��7y�AC�__main__zmath_testcases.txtzcmath_testcases.txtc C s. t �dt �d| ��d }|dk r*|d }|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�n� r �*/usr/local/lib/python3.7/test/test_math.py�to_ulps# s
r c C s� t t| ��} t�| �s t�| �r$| S t�dt�d| ��d }t�dt�d|d ��d }t�|�r�t�dt�d|d ��d }| | S || S dS )a� Return the value of the least significant bit of a
float x, such that the first float bigger than x is x+ulp(x).
Then, given an expected result x and a tolerance of n ulps,
the result y should be such that abs(y-x) <= n * ulp(x).
The results from this function will only make sense on platforms
where native doubles are represented in IEEE 754 binary64 format.
z<qz<dr � N)�abs�float�math�isnan�isinfr r
r )r r
Zx_nextZx_prevr r r �ulp4 s
r c C s | rdt | | d @ � S dS )zANumber of '1' bits in binary expansion of a nonnnegative integer.r r )�count_set_bits)r
r r r r a s r c C sD || d? }|sdS |dkr | S | | dB }t | |�t ||� S dS )z�Product of integers in range(start, stop, 2), computed recursively.
start and stop should both be odd, with start <= stop.
r N)�partial_product)�start�stopZ
numfactorsZmidr r r r e s r c C sd d }}xJt t| �� ��D ]6}|t| |d ? d dB | |? d dB �9 }||9 }qW || t| � >