Maybe someone can explain the code to me ?,
how to make it for unsigned int ?
unsigned int truncate( float flt )
Maybe someone can explain the code to me ?,
how to make it for unsigned int ?
unsigned int truncate( float flt )
Maybe someone can explain the code to me ?,
how to make it for unsigned int ?
unsigned int truncate( float flt )
those are the details, you should be sure if you want to dig such
details of maybe coding the gameplay
as far as i know fpu has 4 rounding modes : to +inf , to -inf, to zero,
and rounding
rounding is the fpu default, but c float->int is defined as 'to zero' (truncation)
this code above takes float substracts 0.5 then stores int with rounding
so this is working such way(if i am not mistaken, probably no)
1.3 -> 0.8 -> 1
1.8 -> 1.3 -> 1
-1.3 -> -1.8 -> -2
-1.8 -> -2.3 -> -2
so it seems that it emulates truncation only for int values > 0
probably floats from 0 to about 2 147 483 647 will be correctly converted
according to some info i found
"If the value being stored is too large for the destination format, is an , is a NaN, or is in an unsupported format and if the invalid-arithmetic-operand exception (#IA) is unmasked, an invalid-operation exception is generated and no value is stored in the destination operand. If the invalid-operation exception is masked, the integer indefinite value is stored in the destination operand."
if float would be bigger than about 2 147 483 647 no value would be stored in outpput int or "integer indefinite value " would be stored
which i do not know what is
so if you would use it for unsigneds or cast minus values it should be modified like
if (f<0) i = - truncate( -f );
and other faster algorithm used, same with larger unsigned
values (i thing fistp for unsigneds is unavaliable in fpu instruction set i am not sure)
I was using cvttss2si which mean "Convert one single-precision floating-point number from xmm/m32 to one signed doubleword integer r32 using truncation." and is more effective i think, this
instruction is avaliable in pentium4 and later - i was decided to use it along with other option use fist procedure for rounding
Yeah, make topics until we are professor.
I am only moderately experienced (I think I need at least 5 (10?20?) years of work yet to be a professor ;/
this indefinite integer value is probably 80000000H,
cpu has many quirks so optymising the x86 is probably a work of lot of quirks to know