BBC BASIC for Windows
Programming >> Assembly Language Programming >> frndint - FPU math.floor() or INT http://bb4w.conforums.com/index.cgi?board=assembler&action=display&num=1257852422 frndint - FPU math.floor() or INT
Post by Michael Hutton on Nov 10th, 2009, 10:27am
I've recently come across a problem of trying to emulate the INT function in assembler. After doing a bit of looking I see that INT is eqivalent to the math.floor() C++ function. Unfortunately frnint rounds to the nearest integer, which is not what I want. The other problem is that the math.floor function is incredibly slow as the FPU rounding state must be changed before converting and then back again afterwards.
Richard, how does BB4W implement INT? Or would it be faster if I implement the trick shown in the above link?
Michael
Re: frndint - FPU math.floor() or INT
Post by admin on Nov 10th, 2009, 5:06pm
Quote:
how does BB4W implement INT?
In terms of actual code it does it quite differently for 40-bit floats and 64-bit floats. For 40-bit floats it truncates towards zero, then if the original number was negative and non-integer it subtracts one from the result.
For 64-bit floats it switches the FPU to 'round towards negative infinity' mode, uses the frndint instruction, then switches the FPU back to its normal rounding mode.