Ñò
mÈKc           @   sÃ   d  Z  d d k l Z e d d d ƒ[ d d k Z d d d	 g Z e i d
 ƒ Z y d	 e f d „  ƒ  YZ Wn e	 j
 o d Z n Xd „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d S(   s8  General floating point formatting functions.

Functions:
fix(x, digits_behind)
sci(x, digits_behind)

Each takes a number or a string and a number of digits as arguments.

Parameters:
x:             number to be formatted; or a string resembling a number
digits_behind: number of digits behind the decimal point
iÿÿÿÿ(   t   warnpy3ks2   the fpformat module has been removed in Python 3.0t
   stackleveli   Nt   fixt   scit
   NotANumbers-   ^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.6/fpformat.pyR      s   s   fpformat.NotANumberc         C   sª   t  i |  ƒ } | d j o t |  ‚ n | i d d d d ƒ \ } } } } | d j o
 d } n | o | d } n | o t | d ƒ } n d } | | | | f S(	   sÅ   Return (sign, intpart, fraction, expo) or raise an exception:
    sign is '+' or '-'
    intpart is 0 or more digits beginning with a nonzero
    fraction is 0 or more digits
    expo is an integeri   i   i   i   t   +t    i    N(   t   decodert   matcht   NoneR   t   groupt   int(   t   st   rest   signt   intpartt   fractiont   exppartt   expo(    (    s   /usr/lib/python2.6/fpformat.pyt   extract#   s     $ 
  c         C   s¾   | d j oL t  | ƒ } |  | |  | | }  } | | j o |  d | | }  q´ n\ | d j  oN t  |  ƒ } |  |  |  | | }  } | | j  o d | | | } q´ n |  | f S(   s5   Remove the exponent by changing intpart and fraction.i    t   0(   t   len(   R   R   R   t   ft   i(    (    s   /usr/lib/python2.6/fpformat.pyt   unexpo2   s    c         C   sg  t  | ƒ } | | j o |  | d | | f St  |  ƒ } | | d j  o d | d f S|  | } | | | } | d j o® | | d } xL | d j o$ | | d j o Pn | d } q“ Wd | } | d } d } | |  t t | | ƒ d ƒ d t  | ƒ | d } | |  | | }  } n | d j o |  | |  f S|  |  d | d f Sd S(   s*   Round or extend the fraction to size digs.R   i    R   t   5i   t   9N(   R   t   chrt   ord(   R   R   t   digsR   R   t   totalt	   nextdigitt   n(    (    s   /usr/lib/python2.6/fpformat.pyt	   roundfrac@   s.    
  

8c         C   s÷   t  |  ƒ t  d ƒ j o t |  ƒ }  n y t |  ƒ \ } } } } Wn t j
 o |  SXt | | | ƒ \ } } t | | | ƒ \ } } x' | o | d d j o | d } q W| d j o
 d } n | d j o | | d | S| | Sd S(   s‡   Format x as [-]ddd.ddd with 'digs' digits after the point
    and at least one digit before.
    If digs <= 0, the point is suppressed.R   i    R   i   t   .N(   t   typet   reprR   R   R   R#   (   t   xR   R   R   R   R   (    (    s   /usr/lib/python2.6/fpformat.pyR   Z   s         
 c         C   sÑ  t  |  ƒ t  d ƒ j o t |  ƒ }  n t |  ƒ \ } } } } | ph x1 | o) | d d j o | d } | d } qK W| o# | d | d } } | d } qÝ d } n. | t | ƒ d } | d | d | } } t d | ƒ } t | | | ƒ \ } } t | ƒ d j o6 | d | d | d  | t | ƒ d } } } n | | } | d j o | d | } n t t | ƒ ƒ } d d t | ƒ | } | d j  o d | } n d	 | } | d
 | S(   s¥   Format x as [-]d.dddE[+-]ddd with 'digs' digits after the point
    and exactly one digit before.
    If digs is <= 0, one digit is kept and the point is suppressed.R   i    R   i   iÿÿÿÿR$   i   t   -R   t   e(   R%   R&   R   R   t   maxR#   t   abs(   R'   R   R   R   R   R   R   R)   (    (    s   /usr/lib/python2.6/fpformat.pyR   j   s8      

 
  
c          C   s[   y; x4 t  d ƒ \ }  } |  Gt |  | ƒ Gt |  | ƒ GHq Wn t t f j
 o n Xd S(   s   Interactive test run.s   Enter (x, digs): N(   t   inputR   R   t   EOFErrort   KeyboardInterrupt(   R'   R   (    (    s   /usr/lib/python2.6/fpformat.pyt   testŠ   s    &(   t   __doc__t   warningsR    t   ret   __all__t   compileR	   t
   ValueErrorR   t	   TypeErrorR   R   R#   R   R   R/   (    (    (    s   /usr/lib/python2.6/fpformat.pyt   <module>   s    					 