1. How can I pass an atom to a C function as C float or double
- Posted by myotis at xnet.ro Sep 12, 2003
- 328 views
Please tell me how can I pass an atom as a C float to a C function from a dll. The same question is for a C double ... Example of the C function in DLL : float MyFunction( float parameter1, double parameter2 ); I have tried all the posible combinations ( C_FLOAT in define the C function, atom_to_float32 when I pass the arguments ... nothing work ) Please write to me a little piece of euphoria code that call this function in Euphoria. Also tell me the calling convention you are write for ... I can change this in my DLL as I want. Also, please tell me if the version of euphoria you are writeing for the example, matter for some reason. Thank you !
2. Re: How can I pass an atom to a C function as C float or double
- Posted by euman at bellsouth.net Sep 13, 2003
- 339 views
On 12 Sep 2003 at 23:27, myotis at xnet.ro wrote: > Please tell me how can I pass an atom as a C float to a C > function from a dll. The same question is for a C double ... > > Example of the C function in DLL : > > float MyFunction( float parameter1, double parameter2 ); > > I have tried all the posible combinations ( C_FLOAT in define the C > function, atom_to_float32 when I pass the arguments ... nothing work ) > > Please write to me a little piece of euphoria code that call this > function in Euphoria. Also tell me the calling convention you are write > for ... > I can change this in my DLL as I want. > > Also, please tell me if the version of euphoria you are > writeing for the example, matter for some reason. > > Thank you ! Can you try this: integer junk junk = allocate(5) poke(junk, atom_to_float32(x)) poke4(junk+1, atom_to_float64(y)) then pass your params the pointer to "junk" f = Myfunction(peek(junk),peek4(junk+1))
3. Re: How can I pass an atom to a C function as C float or double
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 13, 2003
- 331 views
myotis at xnet.ro wrote: > Please tell me how can I pass an atom as a C float to a C > function from a dll. The same question is for a C double ... Elliott was correct in his message. There are a couple of things to watch out for though... > Example of the C function in DLL : > > float MyFunction( float parameter1, double parameter2 ); > > I have tried all the posible combinations ( C_FLOAT in define the C > function, atom_to_float32 when I pass the arguments ... nothing work ) Don't use atom_to_float32() for passing arguments. Just pass the atom value directly as an argument. > Please write to me a little piece of euphoria code that call this > function in Euphoria. Also tell me the calling convention you are write > for ... > I can change this in my DLL as I want. I recommend that you use the __stdcall calling convention when defining the C routine that you are calling from Euphoria. There's a problem when you try to return a floating-point value to exw.exe using the other convention, __cdecl. Watcom C (used to build exw.exe) doesn't handle floating-point return values correctly when it's __cdecl. __cdecl is the default convention with most C compilers. (If you translate your program to C, and compile with Borland, it should be ok.) > Also, please tell me if the version of euphoria you are > writeing for the example, matter for some reason. 2.3 should work fine, but 2.4 has some enhancements in this area, such as __cdecl support (for most things), error tracebacks when a machine-level exception happens, enhanced define_c_proc()/func(), etc. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
4. Re: How can I pass an atom to a C function as C float or double
- Posted by euman at bellsouth.net Sep 13, 2003
- 322 views
<?xml version="1.0" ?><html> <head> <title></title> </head> <body> <div align="left"><font face="Arial"><span style="font-size:10pt">Is this better Elliott? Robert?</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">(C DLL)</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">her_dll</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">float CRoutine( float parameter1, double parameter2 ); </span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">(Euphoria code)</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">atom junk, x, y</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">x = 0.45</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">y = 0.4534 </span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">junk = allocate(16) -- 4 (float) + 8(Double)</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">poke(junk, atom_to_float32(x))</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">poke4(junk+4, atom_to_float64(y))</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">constant </span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">Myfunction = define_c_func(her_dll,"CRoutine",{C_FLOAT, C_DOUBLE}, C_FLOAT)</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">f = c_func(Myfunction,{peek(junk),peek4u(junk+4)}) -- byref</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">f = c_func(Myfunction,{junk,junk+4}) -- byval</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Hope this is more correct than the last post I made after 16 hours</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">behind this darn thing. Oh yeah, Thanks Elliott, Rob</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Euman</span></font></div> <div align="left"><br/></div> <div align="left"></div>
5. Re: How can I pass an atom to a C function as C float or double
- Posted by euman at bellsouth.net Sep 13, 2003
- 328 views
{{{ I dont know what the deal is with my mail being delivered html. sorry folks, I'll get right on that problem too, didnt start till this morning.
Is this better Elliott? Robert?
(C DLL) her_dll float CRoutine( float parameter1, double parameter2 );
(Euphoria code) atom junk, x, y x = 0.45 y = 0.4534 junk allocate(16) 4 (float) + 8(Double) poke(junk, atom_to_float32(x)) poke4(junk+4, atom_to_float64(y))
constant Myfunction define_c_func(her_dll,"CRoutine",{C_FLOAT, C_DOUBLE}, C_FLOAT)
f = c_func(Myfunction,{peek(junk),peek4u(junk+4)}) byref f = c_func(Myfunction,{junk,junk+4}) byval
Hope this is more correct than the last post I made after 16 hours behind this darn thing. Oh yeah, Thanks Elliott, Rob
Euman H2O Software, Inc.
6. Re: How can I pass an atom to a C function as C float or double
- Posted by jbrown105 at speedymail.org Sep 13, 2003
- 343 views
On Sat, Sep 13, 2003 at 10:49:25AM -0400, euman at bellsouth.net wrote: > > I dont know what the deal is with my mail being delivered html. > sorry folks, I'll get right on that problem too, didnt start till this > morning. > > Is this better Elliott? Robert? > > (C DLL) > her_dll > float CRoutine( float parameter1, double parameter2 ); > > (Euphoria code) > atom junk, x, y > x = 0.45 > y = 0.4534 > junk = allocate(16) -- 4 (float) + 8(Double) > poke(junk, atom_to_float32(x)) > poke4(junk+4, atom_to_float64(y)) > > constant > Myfunction = define_c_func(her_dll,"CRoutine",{C_FLOAT, C_DOUBLE}, C_FLOAT) > > f = c_func(Myfunction,{peek(junk),peek4u(junk+4)}) -- byref > f = c_func(Myfunction,{junk,junk+4}) -- byval Well, f = c_func(Myfunction, {junk,junk+4}) -- byREF would work as byref, but then the declaration would have to be constant Myfunction = define_c_func(her_dll,"CRoutine",{C_POINTER, C_POINTER}, C_FLOAT) and the C code would have to be float CRoutine( float * parameter1, double * parameter2 ); As for byval, you dont need the allocate() nor the atom_to_floatXX(), just call the function like so f = c_func(Myfunction,{x, y}) > > Hope this is more correct than the last post I made after 16 hours > behind this darn thing. Oh yeah, Thanks Elliott, Rob > > Euman > H2O Software, Inc. > > > > TOPICA - Start your own email discussion group. FREE! -- Outlook Users, please don't put my email address in your address book. That way, my email address won't appear in forged emails sent by email viruses. (Which are technically worms btw :P) -- Linux User:190064 Linux Machine:84163
7. Re: How can I pass an atom to a C function as C float or double
- Posted by jbrown105 at speedymail.org Sep 13, 2003
- 330 views
Putting in some points I forgot to mention before. On Sat, Sep 13, 2003 at 11:28:37AM -0400, jbrown105 at speedymail.org wrote: > > > On Sat, Sep 13, 2003 at 10:49:25AM -0400, euman at bellsouth.net wrote: > > > > I dont know what the deal is with my mail being delivered html. > > sorry folks, I'll get right on that problem too, didnt start till this > > morning. > > > > Is this better Elliott? Robert? > > > > (C DLL) > > her_dll > > float CRoutine( float parameter1, double parameter2 ); > > > > (Euphoria code) > > atom junk, x, y > > x = 0.45 > > y = 0.4534 > > junk = allocate(16) -- 4 (float) + 8(Double) > > poke(junk, atom_to_float32(x)) > > poke4(junk+4, atom_to_float64(y)) > > > > constant > > Myfunction = define_c_func(her_dll,"CRoutine",{C_FLOAT, C_DOUBLE}, C_FLOAT) > > > > f = c_func(Myfunction,{peek(junk),peek4u(junk+4)}) -- byref > > f = c_func(Myfunction,{junk,junk+4}) -- byval > > Well, > > f = c_func(Myfunction, {junk,junk+4}) -- byREF > > would work as byref, but then the declaration would have to be > > constant > Myfunction = define_c_func(her_dll,"CRoutine",{C_POINTER, C_POINTER}, C_FLOAT) > > and the C code would have to be > > float CRoutine( float * parameter1, double * parameter2 ); Should be noted, that in C, you can either pass byref (via pointers) or by val, but rarely both ... you have to pick one method or another. > > As for byval, you dont need the allocate() nor the atom_to_floatXX(), just > call the function like so > > f = c_func(Myfunction,{x, y}) Remember here, that x and y will be converted to the correct floating point type automaticly by the interpreter. > > > > > Hope this is more correct than the last post I made after 16 hours > > behind this darn thing. Oh yeah, Thanks Elliott, Rob > > > > Euman > > H2O Software, Inc. > > > > > > TOPICA - Start your own email discussion group. FREE! > > -- > Outlook Users, please don't put my email address in your address book. That > way, > my email address won't appear in forged emails sent by email viruses. (Which > are > technically worms btw :P) > -- > Linux User:190064 > Linux Machine:84163 > > > > TOPICA - Start your own email discussion group. FREE! > > -- Outlook Users, please don't put my email address in your address book. That way, my email address won't appear in forged emails sent by email viruses. (Which are technically worms btw :P) -- Linux User:190064 Linux Machine:84163
8. Re: How can I pass an atom to a C function as C float or double
- Posted by Diana Nistor <myotis at xnet.ro> Sep 13, 2003
- 323 views
First of all : Tkank's to all people for helping me. I send this message again because I think I have trobles with my email client and I don't know If the last message=20 was posted ... I read all your messages and I test again all the ways. -------------- Al Getz said :=20 -------------- Uh, for pass by value, what are you using pointers for? Simply define the= =20 function with C_FLOAT or C_DOUBLE and use the atom as the parameter. ----------------------------- I can tell you Al Getz that : ----------------------------- 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 ... Example : // C function in dll ( calling convention is ) : void MyFunction(float ParameterA); -- Euhporia : constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_FLOAT}) procedure MyFunction(atom ParameterA) c_proc(xMyFunction, ParameterA) end procedure -- give diffrent values in ParameterA ... the function in DLL will always -- receive something else !!!!! ------------------- Robert Craig said : ------------------- Don't use atom_to_float32() for passing arguments. Just pass the atom value directly as an argument. ----------------------------- I can tell you Robert Craig : ----------------------------- I explained to Al Getz that this method doesn't work. I don't know the reason but this is it and nobody seems to know this.=20 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 ? Probably because this is not working ... ( I have all the archive downloaded ... I search for keywords like : C_FLOAT and there is nothing in all the files ... ) Anyway thank you very much for the observation on calling=20 convention.=20 It is a god example. Thank's a lot. In conclusion all the peoples around here gives me the same solution : to poke the float value in to memory and give to the dll a pointer to that value. It is an working solution but what we are doing when we have to give to an function in a dll a FLOAT value BY VALUE. Why there is the "C_FLOAT" constant in defining a C function when it does't work ? I think this is a verry big bug in Euphoria. And it cause to me a lot of troubles. Please try yourself and somebody tell to me that I am wrong. EXAMPLE : // C function in dll ( calling convention is ) remain the same : void MyFunction(float ParameterA); -- but in euphoria I define the function like this : constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_INT}) -- then in the procedure I did the magic thing : procedure MyFunction(atom ParameterA) ParameterA =3D bytes_to_int(atom_to_float32(ParameterA)) c_proc(xMyFunction, ParameterA) end procedure Please tell me what you think about this ... I did some tests and it work. The problem is that is slow. The best solution is : somebody to fix this bug in euphoria interpreter. In my case I can modify the dll. But what is happening when somebody want to link to a dll that can not be modified ? I have a friend here in romania working at a 3D engine that use all over the float type ... to port to euphoria it had to change over 100 functions float arguments ! You can say : make all double ... this mean double memory in use ... and he needs only float ( enogh for him ). Diana Nistor myotis at xnet.ro =0D =0D Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate varian= tele lor.=0D Va rugam sa luati in considerare ca exista un risc de fiecare data cand des= chideti=0D fisiere atasate si ca MobiFon nu este responsabila pentru nici un prejudici= u cauzat=0D de virusi.=0D =0D Disclaimer: RAV AntiVirus may not be able to detect all new viruses and var= iants.=0D Please be aware that there is a risk involved whenever opening e-mail attac= hments=0D to your computer and that MobiFon is not responsible for any damages caused= by=0D viruses.=0D
9. Re: How can I pass an atom to a C function as C float or double
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Sep 14, 2003
- 326 views
>From: Diana Nistor <myotis at xnet.ro> >Subject: Re: How can I pass an atom to a C function as C float or double > > >First of all : Thank's to all people for helping me. >I send this message again because I think I have troubles >with my email client and I don't know If the last message=20 >was posted ... > >I read all your messages and I test again all the ways. > >-------------- >Al Getz said :=20 >-------------- >Uh, for pass by value, what are you using pointers for? Simply define the= >=20 >function with C_FLOAT or C_DOUBLE and use the atom as the parameter. > I believe I said that, but OK.... >----------------------------- >I can tell you Al Getz that : >----------------------------- >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 believe ... > I have tried it. In BASS, there is a 3D example, which uses a function to set the position of the music in relation to the user. This works perfectly fine, and you can HEAR the difference too. You just change the Roll off or Doppler factors, and a moving object's sound dynamics will change. >Example : >// C function in dll ( calling convention is ) : >void MyFunction(float ParameterA); > >-- Euphoria : >constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_FLOAT}) > >procedure MyFunction(atom ParameterA) >c_proc(xMyFunction, ParameterA) >end procedure > This should be c_proc(xMyFunction, {ParameterA}) although I don't think it makes much difference. >-- give different values in ParameterA ... the function in DLL will always >-- receive something else !!!!! > >------------------- >Robert Craig said : >------------------- >Don't use atom_to_float32() for passing arguments. >Just pass the atom value directly as an argument. > >----------------------------- >I can tell you Robert Craig : >----------------------------- >I explained to Al Getz that this method doesn't work. >I don't know the reason but this is it and nobody seems to >know this.=20 > >AND A LITTLE QUESTION : Why there is no program in the "archive" >( 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 ? >Probably because this is not working ... >( I have all the archive downloaded ... I search for keywords >like : C_FLOAT and there is nothing in all the files ... ) > Perhaps you haven't read anything I wrote. The OpenGL files use C_FLOAT and they work fine. >Anyway thank you very much for the observation on calling=20 >convention.=20 > >It is a god example. Thank's a lot. > >In conclusion all the peoples around here gives me the same >solution : to poke the float value in to memory and >give to the dll a pointer to that value. It is an working >solution but what we are doing when we have to give >to an function in a dll a FLOAT value BY VALUE. Why >there is the "C_FLOAT" constant in defining a C function >when it does't work ? I think this is a very big bug >in Euphoria. And it cause to me a lot of troubles. >Please try yourself and somebody tell to me that I am wrong. > > >EXAMPLE : >// C function in dll ( calling convention is ) remain the same : >void MyFunction(float ParameterA); > Are you sure about this? Also, is it definitely __stdcall? May I see some of the C code? How do you know the C code doesn't receive the right value? Is the C compiler using big-endian versus little-endian byte order (very unlikely)? >-- but in euphoria I define the function like this : >constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_INT}) > >-- then in the procedure I did the magic thing : >procedure MyFunction(atom ParameterA) > >ParameterA =3D bytes_to_int(atom_to_float32(ParameterA)) > >c_proc(xMyFunction, ParameterA) > >end procedure > >Please tell me what you think about this ... >I did some tests and it work. The problem is that is slow. > >The best solution is : somebody to fix this bug in euphoria interpreter. >In my case I can modify the dll. But what is happening when somebody >want to link to a dll that can not be modified ? I have a friend >here in romania working at a 3D engine that use all over the float >type ... to port to euphoria it had to change over 100 functions float >arguments ! You can say : make all double ... this mean double >memory in use ... and he needs only float ( enough for him ). > I don't see any problems. >Diana Nistor >myotis at xnet.ro >
10. Re: How can I pass an atom to a C function as C float or double
- Posted by Diana Nistor <myotis at xnet.ro> Sep 14, 2003
- 331 views
I really don't know what is the problem with my email program ...=20 Sory for all that "=3D20 ... ". Also, the message I send have some line deleted.=20 I write here again : ------------------------------------------------- I ALSO FOUND MYSELF A SOLUTION TO MY=20 PROBLEM : EXAMPLE : // C function in dll remain the same : void MyFunction(float ParameterA); -- but in euphoria I define the function like this : constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_INT}) -- then in the procedure I did the magic thing : procedure MyFunction(atom ParameterA) ParameterA =3D bytes_to_int(atom_to_float32(ParameterA)) c_proc(xMyFunction, ParameterA) end procedure Please tell me what you think about this ... I did some tests and it work. The problem is that is slow. Sorry again. Diana Nistor =0D =0D Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate varian= tele lor.=0D Va rugam sa luati in considerare ca exista un risc de fiecare data cand des= chideti=0D fisiere atasate si ca MobiFon nu este responsabila pentru nici un prejudici= u cauzat=0D de virusi.=0D =0D Disclaimer: RAV AntiVirus may not be able to detect all new viruses and var= iants.=0D Please be aware that there is a risk involved whenever opening e-mail attac= hments=0D to your computer and that MobiFon is not responsible for any damages caused= by=0D viruses.=0D
11. Re: How can I pass an atom to a C function as C float or double
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Sep 14, 2003
- 335 views
>From: Diana Nistor <myotis at xnet.ro> >Subject: Re: How can I pass an atom to a C function as C float or double > > >I really don't know what is the problem >with my email program ...=20 >Sory for all that "=3D20 ... ". > Sometimes Topica screws it up itself. >Also, the message I send have some line >deleted.=20 I thought they were in the other message.... >I write here again : > > >EXAMPLE : >// C function in dll remain the same : >void MyFunction(float ParameterA); > >-- but in euphoria I define the function like this : >constant xMyFunction =3D define_c_proc(mydll, "MyFunction", {C_INT}) > >-- then in the procedure I did the magic thing : >procedure MyFunction(atom ParameterA) > >ParameterA =3D bytes_to_int(atom_to_float32(ParameterA)) > >c_proc(xMyFunction, ParameterA) > >end procedure > This is technically, the same as the memory thing, but without pointers. Please see other post. >Please tell me what you think about this ... >I did some tests and it work. The problem is that is slow. > >Sorry again. >Diana Nistor > > >=0D >=0D >Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate >varian= >tele lor.=0D >Va rugam sa luati in considerare ca exista un risc de fiecare data cand >des= >chideti=0D >fisiere atasate si ca MobiFon nu este responsabila pentru nici un >prejudici= >u cauzat=0D >de virusi.=0D >=0D >Disclaimer: RAV AntiVirus may not be able to detect all new viruses and >var= >iants.=0D >Please be aware that there is a risk involved whenever opening e-mail >attac= >hments=0D >to your computer and that MobiFon is not responsible for any damages >caused= > by=0D >viruses.=0D > > > >TOPICA - Start your own email discussion group. FREE! > >
12. Re: How can I pass an atom to a C function as C float or double
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 14, 2003
- 330 views
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
13. Re: How can I pass an atom to a C function as C float or double
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Sep 14, 2003
- 339 views
>From: Robert Craig <rds at RapidEuphoria.com> >Subject: Re: How can I pass an atom to a C function as C float or double > >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. > I tried this with Borland and, besides the name not being decorated, it ran fine. >>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. > Still, there are programs in the archive which use C_FLOAT, whether floats are popular or not. And, they do not use any round-about memory methods, either. >Regards, > Rob Craig > Rapid Deployment Software > http://www.RapidEuphoria.com >
14. Re: How can I pass an atom to a C function as C float or double
- Posted by Diana Nistor <myotis at xnet.ro> Sep 14, 2003
- 328 views
SORY, SORY, SORY SORY SORY SORY SORY Thank you Elliott Sales de Andrade. Your last question ( with calling convention )=20 turned on a flash in my dark mind ... yesterday I was played with my dll calling convention and forgot to uncomment this : // The Calling Conventions #define DLL_CC _cdecl=09=09 //#define DLL_CC __stdcall all my functions in dll are defined like this=20 DLL_CC void Function(....); I will recompile the DLL and I will tell you the result. You have a kiss for me but I think this is=20 not enoght for the trobles I cause to you all. I still love Euphoria.=20 I pray to my Euphoria interpretor to forgive my mistake :) SORY. I hope it will work after this. I download BASS ( it wasn't in my list ) nice. Thank you again Elliott Sales de Andrade. Diana ( probably now all peoples over here want's to see me died in a car accident ...=20 and I am not even a queen ... :) =0D =0D Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate varian= tele lor.=0D Va rugam sa luati in considerare ca exista un risc de fiecare data cand des= chideti=0D fisiere atasate si ca MobiFon nu este responsabila pentru nici un prejudici= u cauzat=0D de virusi.=0D =0D Disclaimer: RAV AntiVirus may not be able to detect all new viruses and var= iants.=0D Please be aware that there is a risk involved whenever opening e-mail attac= hments=0D to your computer and that MobiFon is not responsible for any damages caused= by=0D viruses.=0D
15. Re: How can I pass an atom to a C function as C float or double
- Posted by Elliott Sales de Andrade <quantum_analyst at hotmail.com> Sep 14, 2003
- 325 views
>From: Diana Nistor <myotis at xnet.ro> >Subject: Re: How can I pass an atom to a C function as C float or double > >Diana ( probably now all peoples over >here want's to see me died in a car accident ...=20 >and I am not even a queen ... :) Certainly not... There aren't enough female programmers that I've heard of. I mean, there's Judith, she does a lot, and Junko, who co-owns RDS, but other than that, barely any others have posted here. (Unless that means the women are smarter and can figure out their problems without a man's help ;)
16. Re: How can I pass an atom to a C function as C float or double
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 14, 2003
- 328 views
----- Original Message ----- From: "Elliott Sales de Andrade" <quantum_analyst at hotmail.com> To: "EUforum" <EUforum at topica.com> Subject: Re: How can I pass an atom to a C function as C float or double > > > >From: Diana Nistor <myotis at xnet.ro> > >Reply-To: EUforum at topica.com > >To: EUforum <EUforum at topica.com> > >Subject: Re: How can I pass an atom to a C function as C float or double > >Date: Sun, 14 Sep 2003 03:42:14 +0300 > > > >Diana ( probably now all peoples over > >here want's to see me died in a car accident ...=20 > >and I am not even a queen ... :) > > Certainly not... There aren't enough female programmers that I've heard > of. I mean, there's Judith, she does a lot, and Junko, who co-owns RDS, but > other than that, barely any others have posted here. (Unless that means the > women are smarter and can figure out their problems without a man's help ;) There's Kat too, but she has decided to give the forum a break.
17. Re: How can I pass an atom to a C function as C float or double
- Posted by Diana Nistor <myotis at xnet.ro> Sep 14, 2003
- 333 views
Oh, yes I observe myself this percentage ... I don't know if it is good or bad to be a woman and in love with your computer ... Anyway I had a friend that left me alone on my way and I think that was only because of my job=20 and hoby ...=20 maybe that's why the womans generaly use a computer only to buy food=20 because of the man law ...=20 and man hunger :) Diana =0D =0D =0D