Re: How can I pass an atom to a C function as C float or double

new topic     » goto parent     » topic index » view thread      » older message » newer message

Diana Nistor wrote:
> THERE IS A BUG IN EUPHORIA. If I define the function with C_FLOAT and
> use an atom as the parameter there is no error but the value received
> by the function ( in C ... in DLL ) is not the value in the atom !
> This is only for float (4-bytes),=20
> Try yourself if you don't belive ...

I have some test cases for C_FLOAT that I run before any release.
I just tried them again and they work fine. I'll copy one of them
here. It passes a float and a double, and returns a float.

lib = open_dll("\\ctest\\dll\\mytest.dll")
if lib = 0 then
     puts(2, "Couldn't open mytest.dll\n")
     if getc(0) then
     end if
     abort(1)
end if

test2 = define_c_func(lib, "_test2@12", {C_FLOAT, C_DOUBLE}, C_FLOAT)

? c_func(test2, {5.5, -3.7})   -- prints -20.35

=== The C routine looks like:

float __stdcall __export test2(float a, double b)
{
     return a * b;
}

I used Watcom C to make the .dll,
but any Windows C compiler should work.

> AND A LITTLE QUESTION : Why there is no program in the "arhive"
> ( on Euphoria official site ) that call an external c function
> with a float as argument ( not a pointer to float
> or something like this ) ? It is very strange isn't it ?

In C, the float type is not used anywhere near as often as
the double type, and neither is used as often as ints and pointers.
The hardware supports double directly, so double calculations are
at least as fast as float, and give much better accuracy.
The only time you would use float, is when
you have an array of (say) one million floating-point numbers,
and you want to save space, while giving up accuracy.
On a project that I worked on years ago,
we had millions of floating-point numbers coming in to
the machine per second, but these numbers were measurements
from a sensor that was only accurate to about 3 significant digits.
Using 15-digit doubles would have been a waste of memory
with no real improvement in the accuracy of the results.

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu