Returning a float (native Float:)
#1

I hope this isn't any rule violation, but it's somewhat about C.

The idea is to make a native function, which is defined as cell, but returns float.
It should be used as this in pawno :
native Float:function(); //It won't always throw a tag mismatch, but it may prevent unexpected.

I've tried quite a lot of things, but only now i got the solution in plugin writting (In C):
Quite reliable one...
cell result; // Prevents any convertation on return;
float floatresult=0.2*0.5/0.5334+24.2-32.1; // Don't point out that it's anyway going to be precompiled
memcpy(&result,&floatresult,4);
return result;
Quite fast one... (It must be faster!)
It depends on compiler, but with MS VC 8:
cell result;
float floated;
_asm mov eax,floated;
_asm mov result, eax;
return result;
Basically :
move floated to result through eax, avoiding any types, but very, very, very careful with sizes on this one!
Ones could write a very long tutorial about this, but it's a basic description, those who can write a plugin should understand enough of what it does.
But I'm not very good with assembler.. So should I do:
_asm xor eax,eax;
Reply
#2

Have you tried
Код:
return amx_ftoc(floatresult);
?
Reply
#3

Quote:
Originally Posted by xxmitsu
Посмотреть сообщение
Have you tried
Код:
return amx_ftoc(floatresult);
?
Indeed, although I would (well, now i did) expect it to make conversation to int O_o, it's quite weird macro, but thanks, as it does it even better.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)