Hello,

I've searched through the board and in the Raymond's tutorials but I wasn't able to find an answer...

Is there a way to know if a number, currently retained on the FPU, has a decimal part (I mean "something after the '.').

For example, my program take a number inputed by user, then compute the square root of this number.

user input : 100
result: 10. (no decimal part here)

user input : 99
result: 9.94987... (decimal part here)

I've looked for the status and control words, but it seems they can't tell me if there's a decimal part.

What should I do ?

Thank you very much.

Regards, Neitsa.
Posted on 2005-02-11 15:57:55 by Neitsa
Need to round number to integer and subtract to get fractional part.

Instruction FRNDINT should work.
Posted on 2005-02-11 18:47:43 by bitRAKE
i used this code (from delphi rtl)
when i needed to do the same thing
``````	fld st
push 1F320000h
fnstcw [esp]
fldcw [esp+2]
frndint
fldcw [esp]
fsub
fldz
fcompp
fnstsw ax
sahf
je nothing after the '.'
``````
Posted on 2005-02-11 18:49:20 by drizz
Maybe you're already aware of this but I feel the need to point out that because of the impercission of finite machines some numbers which you may load into the FPU as integers will end up haveing a small decimal bit.
Posted on 2005-02-11 20:21:15 by Eóin
If you are programming for the Pentiums or higher, you could use the following. From the tutorial, you will understand the idea. Assuming the number you want to examine is already in ST(0) and ST(7) is still free:

``````fld  st           ;make copy
frndint           ;round it to an integer
fcomip st,st(1)    ;compare, pop the integer and set CPU flags
jnz  contains_decimal``````

All the FPU data registers are still in the same state as before the above code. Good enough? Just make sure to use the .686 directive to assemble.

Raymond
Posted on 2005-02-11 22:00:21 by Raymond
Hello,

I was doing approximately the same thing but I wasn't sure it was "the thing to do without errors".

And Raymond, thank you for your tutorials on FPU, they are great !

Regards, Neitsa.
Posted on 2005-02-12 07:07:22 by Neitsa
Neitsa

Thanks for the appreciation. Very kind of you.

Raymond
Posted on 2005-02-12 15:49:40 by Raymond
Just to point out the fcomip instruction needs a Pentium Pro CPU minimum.
Posted on 2005-02-12 19:41:33 by x86asm