BBC BASIC for Windows
« frndint - FPU math.floor() or INT »
Welcome Guest. Please Login or Register. Apr 5th, 2018, 10:29pm
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
If you require a dump of the post on your message board, please come to the support board and request it.
frndint - FPU math.floor() or INT
« Thread started 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.
Re: frndint - FPU math.floor() or INT
« Reply #1 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.