ฦ
ึM๖9c       sธ     d  Z    d k Z  e i d  Z  y  d e f d     YZ Wn  e j
 o  d Z n X d   Z - d   Z ; d   Z	 U d	   Z
 e 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-   ^([-+]?)0*(\d*)((?:\.\d*)?)(([eE][-+]?\d+)?)$s
   NotANumberc      s     RS(   N(    (    s%   /mit/python/lib/python2.0/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   ress   signs   intparts   fractions   expparts   expos%   /mit/python/lib/python2.0/fpformat.pys   extract s    ' 
 
 	c    s๓   - . / | d j o] 0 t |  } 1 |  | |  | | f \ }  } 2 | | j o 3 |  d | | }  n np 4 | d j  o_ 5 t |   } 6 |  |  |  | | f \ }  } 7 | | j  o 8 d | | | } n n 9 |  | 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   is%   /mit/python/lib/python2.0/fpformat.pys   unexpo- s   !!c    sภ  ; < = t  |  } > | | j o ? |  | d | | f Sn @ t  |   } A | | d j  o B d | d f Sn C |  | } D | | | } E | d j oิ F | | d } G xa G | d j o- H | | d j o H Pn I | d } qภ WK d | } L | d } M d } N | |  t	 t
 | |  d  d t  |  | d } O | |  | | f \ }  } n P | d j o Q |  | |  f Sn S |  |  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   totals	   nextdigits   ns%   /mit/python/lib/python2.0/fpformat.pys	   roundfrac; s0     	;!c    s.  U X Y t  |   t  d  j o Y |  }  n Z y [ t |   \ } } } } Wn \ t j
 o ] |  Sn X^ t | | |  \ } } _ t	 | | |  \ } } ` x- ` | o | d d j o ` | d } qฎ Wa | d j o a d } n b | d j o b | | d | Sn c | | 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   signs   intparts   fractions   expos%   /mit/python/lib/python2.0/fpformat.pys   fixU s"        c    s2  e h i t  |   t  d  j o i |  }  n j t |   \ } } } } k | o l x: l | o | d d j o m | d } n | d } q\ Wo | o. p | d | d f \ } } q | d } n
 s d } n9 u | t |  d } v | d | d | f \ } } w t d |  } x t
 | | |  \ } } y t |  d j o> z | 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   s   .i   s   -s   +s   eN(   s   types   xs   extracts   signs   intparts   fractions   expos   lens   maxs   digss	   roundfracs   ss   abss   e(   s   xs   digss   signs   intparts   fractions   expos   ss   es%   /mit/python/lib/python2.0/fpformat.pys   scie s8     
!>  c     s      yP  xF  d o;  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   digss%   /mit/python/lib/python2.0/fpformat.pys   test s    
+(   s   __doc__s   res   compiles   decoders
   ValueErrors
   NotANumbers	   TypeErrors   extracts   unexpos	   roundfracs   fixs   scis   test(    s%   /mit/python/lib/python2.0/fpformat.pys   ? s    