From: William S F. <ws...@fu...> - 2006-09-27 20:56:49
|
Steven Damer wrote: > I'm seeing a problem with moving double values from C to python. > Values from C are being converted into large integer values in python > - for example, 3.5 is converted to 1080033280.0. Here's the test code > that I wrote: > C file: > float testfloat() > { > return 3.5; > } > > int testint() > { > return 3; > } > > double testdouble() > { > return 3.5; > } > > float testfloatreflect(float f) > { > return f; > } > > double testdoublereflect(double d) > { > return d; > } > > int testintreflect(int i) > { > return i; > } > > .i file > extern float testfloat(); > extern int testint(); > extern double testdouble(); > extern float testfloatreflect(float f); > extern double testdoublereflect(double d); > extern int testintreflect(int i); > Output that I get in python: >>>> import NFGames >>>> NFGames.testint() > 3 >>>> NFGames.testfloat() > 1080033280.0 >>>> NFGames.testdouble() > 1.0 >>>> NFGames.testintreflect(4) > 4 >>>> NFGames.testfloatreflect(4.5) > 0.0 >>>> NFGames.testdoublereflect(4.5) > 1074921472.0 > > I suspect that I'm seeing memory addresses instead of values, but I'm > not sure why, or what I need to do to correct it. Thanks for looking > at this. > You don't mention any versions of anything. I just checked and it works for me using swig-1.3.29, python-2.4.2, gcc-4.1 and I'd be surprised if it doesn't work on any other platform as it is a pretty common scenario. I suggest you look at your compiler flags and/or use a C debugger to test what the matter is. Also suggest you run the tests that come with SWIG to check that the known working cases are working... run 'make check-python-test-suite' in the top level directory or run the examples in Examples/python. William |