[Python-Dev] creating Lib/tests/cmath_testcases.txt for 64 bit complex numbers (text)
dickinsm at gmail.com
Mon Sep 10 22:25:23 CEST 2012
On Mon, Sep 10, 2012 at 9:06 PM, Matti Picus <matti.picus at gmail.com> wrote:
> Can the authors of the original file help me reconstruct the scripts or
> programs used to generate it, and reformulate them for 32 bit floats?
I used a ctypes wrapper around the MPFR library for most of the
testcases, though some were generated by hand. I later pushed a
version of the MPFR wrapper to PyPI under the name 'bigfloat', but
unfortunately haven't had time to maintain it; it may or may not work
right now. (IIRC, version 0.2 should work okay; I'd started a
rewrite using Cython instead of ctypes and then got bogged down in
Python 2 / Python 3 distribution fun. The source at
https://bitbucket.org/dickinsm/bigfloat/src is functional, but doesn't
have distribution sorted out.)
I also used Pari/GP to spot check some of the results.
And that only gets you halfway there, since MPFR only does the real
parts; it's still necessary to implement the formulas for the real
and imaginary parts in each case, using as much additional precision
as necessary to compute intermediate results. I used a simple
'peeling the onion' approach, computing lower and upper bounds for the
values in each case and extending precision until both the lower and
upper values gave the same result when rounded to 53 bit precision.
At the time I did this, I don't think the MPC library existed in
usable form; that may make life easier.
You should also look at Gmpy2 ; I believe the most recent release
supports MPC and MPFR. That's probably the simplest way forward.
Note that MPFR doesn't support IEEE subnormals out of the box, though
it provides some convenience functions to make it relatively easy to
add subnormal support. That was one of my motivations for writing
I'm afraid I don't have the exact scripts that I used any more;
they're sitting on the hard drive of a defunct computer that's
More information about the Python-Dev