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.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: frndint - FPU math.floor() or INT  (Read 911 times)
Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx 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.


http://books.google.com.au/books?id=M2QYbTVd0VgC&pg=PA169&lpg=PA169&dq=fpu+tricks&source=bl&ots=K4r_fAtJVX&sig=TpIRX1gnNiYXklH4SQH99TtGtHc&hl=en&ei=xTf5SoGvMM6fkQX97LDCCw&sa=X&oi=book_result&ct=result&resnum=3&ved=0CA0Q6AEwAg#v=onepage&q=fpu%20tricks&f=false

Richard, how does BB4W implement INT? Or would it be faster if I implement the trick shown in the above link?

Michael
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls