ó
	Q[c           @   sZ   d  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 d S(   sD   
``python-future``: pure Python implementation of Python 3 round().
iÿÿÿÿ(   t   PYPYt   PY26t   bind_method(   t   Decimalt   ROUND_HALF_EVENc         C   sù   t  } | d k r! t } d } n  t |  d  r= |  j |  S| d k  rX t d   n  t d  | } t r d t t	 |    k r t
 |   }  q n  t sÀ t j |   j | d t } n t |   j | d t } | rë t |  St
 |  Sd S(   s©  
    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.
    i    t	   __round__s"   negative ndigits not supported yett   10t   numpyt   roundingN(   t   Falset   Nonet   Truet   hasattrR   t   NotImplementedErrorR   R    t   reprt   typet   floatR   t
   from_floatt   quantizeR   t   from_float_26t   int(   t   numbert   ndigitst
   return_intt   exponentt   d(    (    s7   lib/python2.7/site-packages/future/builtins/newround.pyt   newround   s&    	
c   	      C   sæ   d d l  } d d l m } t |  t t f  r; t |   S| j |   sY | j |   ri t t	 |    S| j
 d |   d k r d } n d } t |   j   \ } } d   } | |  d } | | t | d |  |  } | S(	   sî  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')

    iÿÿÿÿN(   t   _dec_from_tripleg      ð?i    i   c         S   s.   |  d k r& t  t t |     d Sd Sd  S(   Ni    i   (   t   lent   bint   abs(   R   (    (    s7   lib/python2.7/site-packages/future/builtins/newround.pyt
   bit_lengthY   s    i   (   t   matht   decimalR   t
   isinstanceR   t   longR   t   isinft   isnanR   t   copysignR   t   as_integer_ratiot   str(	   t   ft   _mathR   t   signt   nR   R   t   kt   result(    (    s7   lib/python2.7/site-packages/future/builtins/newround.pyR   7   s    
		!R   N(   t   __doc__t   future.utilsR    R   R   R!   R   R   R
   R   R   t   __all__(    (    (    s7   lib/python2.7/site-packages/future/builtins/newround.pyt   <module>   s
   +	,