The behaviour of the FPU can be modified to round results to the nearest value, or up or down or just truncated. The flags for doing this are located in the 16 bit control register. This is accessible with the instructions FLDCW (load control word) and FSTCW (store control word).
It is also possible to control the precision if necessary. The Extended precision format which is native to the FPU, has 64 bits of precision - this can be reduced if so desired.
This is briefly described in the following article:
http://www.website.masmforum.com/tutorials/fptute/fpuchap1.htm#cword
This demonstrates rounding control on the FPU in PowerBasic
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
DIM f AS DOUBLE
DIM r AS LONG
DIM p AS BYTE PTR
DIM fm AS LONG
DIM fr AS LONG
' set test data
f=-33.6
' save original control word
p=VARPTR(fm)
! fstcw [eax]
' set FPU control word for integer rounding
'fr=fm OR &h0000 ' round to nearest -34
'fr=fm OR &h0400 ' round down towards -ininity -34
'fr=fm OR &h0800 ' round up towards + infinity -33
fr=fm OR &h0c00 ' truncate towoards zero -33
' load control word
p=VARPTR(fr)
! fldcw [eax]
' perform operation
! fld qword f
p=VARPTR(r)
! fistp dword [eax] ' store result
' restore original control word
p=VARPTR(fm)
! fldcw [eax]
MSGBOX STR$(r)
END FUNCTION
Thanks Charles,
another really useful thing to know!
Petr