-í
ç¶<c       s   d  Z  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
Ns   fixs   scis
   NotANumbers-   ^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$c      s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    s   /usr/lib/python2.2/fpformat.pys
   NotANumber s   s   fpformat.NotANumberc    s®   t  i |  ƒ } | t j o t |  ‚ n | i d d d d ƒ \ } } } } | d j o
 d } n | o | d } n | o t | d ƒ } n d } | | | | f Sd 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   s   +s    i    N(   s   decoders   matchs   ss   ress   Nones
   NotANumbers   groups   signs   intparts   fractions   expparts   ints   expo(   s   ss   expparts   ress   signs   expos   fractions   intpart(    (    s   /usr/lib/python2.2/fpformat.pys   extract  s      $ 
  c    sÌ   | d j oQ t | ƒ } |  | |  | | f \ }  } | | j o |  d | | }  n na | d j  oS t |  ƒ } |  |  |  | | f \ }  } | | j  o d | | | } n n |  | f Sd S(   s5   Remove the exponent by changing intpart and fraction.i    s   0N(   s   expos   lens   fractions   fs   intparts   i(   s   intparts   fractions   expos   fs   i(    (    s   /usr/lib/python2.2/fpformat.pys   unexpo/ s     c    su  t  | ƒ } | | j o |  | d | | f Sn t  |  ƒ } | | d j  o d | d f Sn |  | } | | | } | d j o³ | | d } xL | d j o$ | | d j o Pn | d } q™ Wd | } | d } d } | |  t	 t
 | | ƒ d ƒ d t  | ƒ | d } | |  | | f \ }  } n | d j o |  | |  f Sn |  |  d | d f Sd S(   s*   Round or extend the fraction to size digs.s   0i    s    s   5i   s   9N(   s   lens   fractions   fs   digss   intparts   is   totals	   nextdigits   ns   chrs   ord(   s   intparts   fractions   digss   fs   is   ns   totals	   nextdigit(    (    s   /usr/lib/python2.2/fpformat.pys	   roundfrac= s0     
  

8c    sø   t  |  ƒ t  d ƒ j o |  }  n y t |  ƒ \ } } } } Wn t j
 o |  Sn Xt | | | ƒ \ } } t	 | | | ƒ \ } } x' | o | d d j o | d } q W| d j o
 d } n | d j o | | d | Sn	 | | 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.s    i    s   0i   s   .N(   s   types   xs   extracts   signs   intparts   fractions   expos
   NotANumbers   unexpos	   roundfracs   digs(   s   xs   digss   expos   fractions   signs   intpart(    (    s   /usr/lib/python2.2/fpformat.pys   fixW s"      	   
 c    sÚ  t  |  ƒ t  d ƒ j o |  }  n t |  ƒ \ } } } } | om x1 | o | d d j o | d } | d } qG W| o( | d | d f \ } } | d } n d } n3 | t | ƒ d } | d | d | f \ } } t d | ƒ } t
 | | | ƒ \ } } t | ƒ d j o: | d | d | d  | t | ƒ d f \ } } } n | | } | d j o | d | } n t | ƒ } d d t | ƒ | } | d j  o d | } n d	 | } | d
 | Sd 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.s    i    s   0i   iÿÿÿÿs   .i   s   -s   +s   eN(   s   types   xs   extracts   signs   intparts   fractions   expos   lens   maxs   digss	   roundfracs   ss   abss   e(   s   xs   digss   es   ss   expos   fractions   signs   intpart(    (    s   /usr/lib/python2.2/fpformat.pys   scig s8       

:
  
c     sd   yD x= d o5 t  d ƒ \ }  } |  Gt |  | ƒ Gt |  | ƒ GHq WWn t t f j
 o n Xd S(   s   Interactive test run.i   s   Enter (x, digs): N(   s   inputs   xs   digss   fixs   scis   EOFErrors   KeyboardInterrupt(   s   xs   digs(    (    s   /usr/lib/python2.2/fpformat.pys   test‡ s      ((   s   __doc__s   res   __all__s   compiles   decoders
   ValueErrors
   NotANumbers	   TypeErrors   extracts   unexpos	   roundfracs   fixs   scis   test(
   s   scis   __all__s   res   tests   fixs
   NotANumbers   unexpos   decoders	   roundfracs   extract(    (    s   /usr/lib/python2.2/fpformat.pys   ? s   						 