Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-07-13 16:57:48

----- Original Message -----
From: <rwgk_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, July 13, 2001 5:07 PM
Subject: [boost] Re: python patch: convert int/double to complex

> --- 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.

I don't think it's a big deal, but doubles have a maximum exponent. Suppose
DOUBLE_MAX is 2^256. Well, it's easy to imagine a python LONG with more than
256 bits. What happens then?

> 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?

Yes, I'm not worried in the least about losing the least significant digits.

> 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?

Sure; if you think it's a good patch, it's fine by me.


Boost list run by bdawes at, gregod at, cpdaniel at, john at