Re: Problems with C floats
- Posted by mattlewis (admin) Jan 31, 2010
- 2395 views
irv said...
jimcbrown said...
I assume this rules out any and all use of varargs or stdargs ?
Yes, the routine in question needs the following: C_POINTER, C_FLOAT, C_FLOAT, C_FLOAT, C_INT No varargs involved, and the same routine in GTK works correctly when called by a C program.
OK, I updated my test program:
// irv.c // build with $ gcc -shared -fPIC -ldl irv.c -o irv.so #include <stdio.h> void test_float( float foo, double bar, int baz ){ printf( "double: %e\nfloat: %e\nint: %d\n", foo, bar, baz ); } void test_irv( int *ptr, float f1, float f2, float f3, int i ){ printf( "ptr: %p\nf1: %f (%x)\nf2: %f (%x)\nf3: %f (%x)\ni: %d\n", ptr, f1, *(int*)(&f1), f2, *(int*)(&f2), f3, *(int*)(&f3), i ); }
...and the euphoria code:
-- irv.ex include std/dll.e constant irv = open_dll( "./irv.so" ), test_float = define_c_proc( irv, "test_float", {C_FLOAT, C_DOUBLE, C_INT}), test_irv = define_c_proc( irv, "test_irv", {C_POINTER, C_FLOAT, C_FLOAT, C_FLOAT, C_INT} ) c_proc( test_float, { 0.25, 0.75, 9}) c_proc( test_irv, { 0xDEADBEEF, 1, 2, 0.5, 8008135} )
And then I get:
$ gcc --version gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ eui -version Euphoria Interpreter 4.0.0 development (r3061M) for Linux Using System Memory $ eui irv double: 2.500000e-01 float: 7.500000e-01 int: 9 ptr: 0xdeadbeef f1: 1.000000 (3f800000) f2: 2.000000 (40000000) f3: 0.500000 (3f000000) i: 8008135
It all looks correct to me. However, this was with a locally built binary. I grabbed the latest eubin, and I got:
$ ./eui irv double: 4.601707e-34 float: 7.500000e-01 int: 9 ptr: 0xdeadbeef f1: 2.000000 (40000000) f2: 0.500000 (3f000000) f3: 0.000000 (818eaff) i: 8008135
What binary are you using? There's definitely something going on here.
Matt