Hi,
rwosdev wrote:
I wrote an assembly function to get the fractional part of a double (e.g. the '72345' of 20.72345).
It works fine but not with values as precise as 20.723456 where it just ends up in a loop.
It also won't work for values too large to fit in a 64-bit signed integer.
rwosdev wrote:
Any suggestions?
I'd make sure it's not a special value (infinity, NaN), then use "FABS" to make sure it's positive, then use "FXTRACT" to split the number into a significand and an exponent and store these separately as integers to get an unsigned 64-bit integer significand and signed 32-bit integer exponent.
Then I'd shift the significant left by "exponent + 32" (with a bunch of tests to make sure the shift count is in range, and using "right shift by negated value" if its negative; and using SHLD or SHRD if it's 32-bit code where you need to use a pair of registers for a 64-bit integer) to convert the value into fixed point format where the lowest 32 bits are the most significant 32 fractional bits (and anything else is discarded).
After that, it becomes a relatively simple loop (e.g. containing something like "mov ebx,10; mul ebx; add edx,'0'") to get each digit in ASCII.
Cheers,
Brendan