27.12.2010, 14:40
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;
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;