Example #1
0
    def mk_mpc(self, x, y):

        from mpmath import mp, mpc
        from mpmath import mpmathify as mpify

        mp.dps = int(self.prec)

        return mpc( real = mpify(x), imag = mpify(y) )
Example #2
0
def test_mpoint_init(testno):
    test_prec = 15
    print "\n[TEST %d]: MPoint init at %d precision by ..." % (testno, test_prec)

    # setup test dict for 'complex' parameter types
    mpoint_test_d = {
        "complex_mpstr": [ '1.2323429893483498+23.452347567843234655676j', 
                         '1.2323429893483498-23.452347567843234655676j', 
                         '-1.2323429893483498+23.452347567843234655676j', 
                         '-1.2323429893483498-23.452347567843234655676j', ], 
        }
    mpoint_test_d.update( {
            "complex_py": [ complex(p) for p in mpoint_test_d["complex_mpstr"] ] 
            } )

    # ... for coordinate (x,y) paramater types, a shortcut for str coords
    mpoint_test_d.update( { 
            "coord_str": [ (str(p.real), str(p.imag)) 
                             for p in mpoint_test_d["complex_py"] ]
            } )
    mpoint_test_d.update( {
            "coord_ld": [ (p.real, p.imag) for p in mpoint_test_d["complex_py"] ]
            } )

    for test, param_l in mpoint_test_d.iteritems():
        print "==> " + test + ":"
        for param in param_l:
            if 'coord' in test:
                mpt = MPoint(param[0], param[1], test_prec)
            else:
                mpt = MPoint(param, test_prec)
            print "  -> %s\n  =? (%s, %s)" % (param, mpify(mpt.real), mpify(mpt.imag))

    # while we have an MPoint might as well test some other stuff...
    print "==> Testing MPoint.set_mp() and .C() multiprec return methods ..." 
    print "  -> none: ", mpt.C()
    mpt.set_mp('mpmath')
    print "  -> mpmath: ", mpt.C()
    mpt.set_mp('bigfloat')
    print "  -> bigfloat: ", mpt.C()