
    Fwgv                     L    d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 d	dZ
d ZdgZy)
zD
``python-future``: pure Python implementation of Python 3 round().
    )division)PYPYPY26bind_method)DecimalROUND_HALF_EVENNc                    d}|d}d}t        | d      r| j                  |      S t        d      | z  }dt        t	        |             v rt        |       } t        | t              r| }n't        st        j                  |       }nt        |       }|dk  rt        ||z        |z  }n|j                  |t              }|rt        |      S t        |      S )a  
    See Python 3 documentation: uses Banker's Rounding.

    Delegates to the __round__ method if for some reason this exists.

    If not, rounds a number to a given precision in decimal digits (default
    0 digits). This returns an int when called with one argument,
    otherwise the same type as the number. ndigits may be negative.

    See the test_round method in future/tests/test_builtins.py for
    examples.
    FTr   	__round__10numpy)rounding)hasattrr
   r   reprtypefloat
isinstancer   
from_floatfrom_float_26newroundquantizer   int)numberndigits
return_intexponentdresults         O/var/www/horilla/myenv/lib/python3.12/site-packages/future/builtins/newround.pyr   r      s     J
v{#((t}'*H $tF|$$v&'"""6*Af%A{!h,'(2H?6{V}    c                    ddl }ddlm} t        | t        t
        f      rt        |       S |j                  |       s|j                  |       rt        t        |             S |j                  d|       dk(  rd}nd}t        |       j                         \  }}d } ||      dz
  } ||t        |d|z  z        |       }|S )a  Converts a float to a decimal number, exactly.

    Note that Decimal.from_float(0.1) is not the same as Decimal('0.1').
    Since 0.1 is not exactly representable in binary floating point, the
    value is stored as the nearest representable value which is
    0x1.999999999999ap-4.  The exact equivalent of the value in decimal
    is 0.1000000000000000055511151231257827021181583404541015625.

    >>> Decimal.from_float(0.1)
    Decimal('0.1000000000000000055511151231257827021181583404541015625')
    >>> Decimal.from_float(float('nan'))
    Decimal('NaN')
    >>> Decimal.from_float(float('inf'))
    Decimal('Infinity')
    >>> Decimal.from_float(-float('inf'))
    Decimal('-Infinity')
    >>> Decimal.from_float(-0.0)
    Decimal('-0')

    r   N)_dec_from_tripleg      ?   c                 N    | dk7  r t        t        t        |                   dz
  S y)Nr      )lenbinabs)r   s    r   
bit_lengthz!from_float_26.<locals>.bit_length_   s$    6s3q6{#a''r      )mathdecimalr!   r   r   longr   isinfisnanr   copysignr'   as_integer_ratiostr)	f_mathr!   signnr   r(   kr   s	            r   r   r   =   s    * (!c4[!qz{{1~QtAw~~c1$q6""$DAq
 	1AdC!Q$K!4FMr   r   )N)__doc__
__future__r   future.utilsr   r   r   r+   r   r   r   r   __all__ r   r   <module>r<      s/      0 0 -+`)X ,r   