Just a couple of subs I use when I want to truncate a floating point number instead of rounding. During an assignment such as:
int i = 1.77f;
The default FPU mode used by Aurora is a round to the nearest whole number which results in 2.
int i = ftoint(1.77f);
Places the FPU in truncate mode before converting and the result is 1. This is the equivelent code generated in a cast to int in C
// int i = (int)1.77f;
sub dtoint(double d),int64
{
word cw;
word cw2;
int64 ret;
#asm
lea eax,[ebp]
fstcw [eax-4]
mov word [eax-8],0x0F3F
fldcw [eax-8]
fld qword [eax+8]
fistp qword [eax-16]
fldcw [eax-4]
#endasm
return ret;
}
sub ftoint(float f),int
{
word cw;
word cw2;
int ret;
#asm
lea eax,[ebp]
fstcw [eax-4]
mov word [eax-8],0x0F3F
fldcw [eax-8]
fld dword [eax+8]
fistp dword [eax-12]
fldcw [eax-4]
#endasm
return ret;
}
Just wondering .. is that the equivalent of 'Floor' .. :)
Graham
Floor works differently with negative numbers.
Ah yes .. it's like Floor for +ve numbers, and like Ceil for -ve ones ..ÂÃ, :)
I always have to think a bit about negative numbers.
Graham