[Python.NET] RE: Conversion of single precision floating point to
python floats
Brian Lloyd
brian at zope.com
Mon Feb 7 16:40:54 CET 2005
Hi Peter - there is some rounding problem with the
PyFloat_FromDouble approach (if you compile with that
and run the unit tests, you'll see a number of them
fail). The temp string is a workaround for now.
Thanks for the note though - if you have time to find
an approach that lets tests pass and avoids the temp,
I'd be happy to check it in ;)
Brian Lloyd brian at zope.com
V.P. Engineering 540.361.1716
Zope Corporation http://www.zope.com
> -----Original Message-----
> From: Peter Schwalm [mailto:Peter.Schwalm at epost.de]
> Sent: Saturday, February 05, 2005 7:58 PM
> To: Brian Lloyd; pythondotnet at python.org
> Subject: Conversion of single precision floating point to python floats
>
>
> Hi Brian,
>
> I recently had a problem retrieving a float value from a dotNet
> function. I
> had a conversion error which was caused by the local setting of
> the decimal
> separator (a comma here in germany).
>
> I figured out that you have already corrected this problem in
> cvs. Before I
> found these correction I have tried the following version, which I would
> prefer because it does not use an intermediate string for the conversion.
>
> I don't know if you use this intermediate string accidentally -
> possibly for
> the sake of rounding that happens during conversion to a string?
>
> Anyway I would like to communicate my solution (your last cvs version
> commented out):
>
> namespace Python.Runtime {
> ...
> internal class Converter {
> ...
> internal static IntPtr ToPython(Object value, Type type) {
> ...
>
> case TypeCode.Single:
> // string ss = ((float)value).ToString(nfi);
> // IntPtr ps = Runtime.PyString_FromString(ss);
> // IntPtr op = Runtime.PyFloat_FromString(ps, IntPtr.Zero);
> // Runtime.Decref(ps);
> // return op;
> return Runtime.PyFloat_FromDouble((double) ((float)value));
>
> Greetings
> Peter Schwalm
>
>
More information about the PythonDotNet
mailing list