Boost logo

Boost :

From: rwgk_at_[hidden]
Date: 2001-07-13 16:07:02


--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
> Uhh, I guess it's still possible to have a Python long that doesn't
fit in a
> double, isn't it? Probably that case isn't worth worrying about,
but I
> think your current code misses it.

I looked at the source code for PyLong_AsDouble in
Objects/longobject.c. This is at the heart of the
conversion code:

        while (--i >= 0) {
                x = x*multiplier + (double)v->ob_digit[i];
        }

From this I conclude that the least significant digits are
lost for large numbers.

It is also possible that a C long (PyInt) does not fit into
std::complex<float> without losing some digits. Similarly,
a C double (PyFloat) will lose digits when converted to
std::complex<float>. But isn't this what everybody expects?

I do not see a fundamental difference between the PyLong
conversion and the other conversions. Therefore I find the
proposed code acceptable.

David, I would like to add the patch to the CVS tree. OK?

Ralf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk