float unlimited increasing rotation or use a if

Started by
52 comments, last by fir 10 years, 3 months ago

Maybe someone can explain the code to me ?,

how to make it for unsigned int ?

unsigned int truncate( float flt )

S T O P C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70 Working on : LevelContainer class & LevelEditor

Advertisement

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 infinity.gif, 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

RoundToInt:
fld dword [esp+4]
fistp dword [esp-4]
mov eax, dword [esp-4]
ret
attention, this procedure is probably wrong (i not noticed it back then only later) because i use low part of stack ([esp+4] is first argument [esp] is call return adres [esp-4] and more is unused stack but probably can be overvrited if some interrupt will appear - I am not sure because i do not know if interrupts are using the same stack as regular process
(probably no but i am not sure and this way of using down stack is like 'undocumented') :/ well maybe i will make a topic for that maybe someone will answer me

Yeah, make topics until we are professor.

S T O P C R I M E !

Visual Pro 2005 C++ DX9 Cubase VST 3.70 Working on : LevelContainer class & LevelEditor

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

This topic is closed to new replies.

Advertisement