"Fossies" - the Fresh Open Source Software Archive

Member "NZMATH-1.2.0/nzmath/plugin/math/_mpmath.py" (19 Nov 2012, 998 Bytes) of package /linux/misc/old/NZMATH-1.2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "_mpmath.py" see the Fossies "Dox" file reference documentation.

    1 """
    2 mpmath  -- mpmath plug-in
    3 """
    4 
    5 import mpmath
    6 
    7 # mpmath does not provide fmod/pow
    8 def _fmod(x, y):
    9     """
   10     returns x - n * y, where n is the quotient of x / y, rounded
   11     towards zero to an integer.
   12     """
   13     fquot = mpmath.mpf(x) / y
   14     if fquot < 0:
   15         n = -mpmath.floor(-fquot)
   16     else:
   17         n = mpmath.floor(fquot)
   18     return x - n * y
   19 
   20 mpmath.fmod = _fmod
   21 mpmath.pow = mpmath.power
   22 
   23 MATHMODULE = mpmath
   24 CMATHMODULE = mpmath
   25 FLOATTYPE = mpmath.mpf
   26 COMPLEXTYPE = mpmath.mpc
   27 PRECISION_CHANGEABLE = True
   28 
   29 def CHECK_REAL_OR_COMPLEX(testee):
   30     """
   31     Return 1 if testee is a real number, 0 if complex.
   32     If testee is not a complex number, raise an exception.
   33     """
   34     try:
   35         COMPLEXTYPE(testee)
   36     except TypeError:
   37     # not a complex number
   38         raise
   39     try:
   40         FLOATTYPE(testee)
   41         return 1
   42     except TypeError:
   43         return 0
   44 
   45 def SETPRECISION(prec):
   46     """
   47     Set precision.
   48 
   49     prec is the number of bits.
   50     """
   51     mpmath.mp.prec = prec