Tag: fmod

Float Modulo in PureBasic

Posted by on August 27, 2009

I keep forgetting the fact that PB is retarded when it comes to the modulo operator and floating point values!.

It’s time to write our own fmod() equivalent; lucky for us the Intel guys were kind enough as to implement quite a useful instruction called FPREM a few eons ago, which pretty much means “Partial REMinder” and what it does is rather simple: it computes the partial remainder of st(0)/st(1).

Of course with great instructions comes great limitations: in this case we cannot produce the final reminder if the difference between X and Y is bigger than 63. We can solve this by implementing a loop and checking for the C2 bit of the status word to be cleared. This is all explained in the IA32 manuals.

It’s not pretty but until fpu modulo operations are officially supported in the language, this might well be your only sane choice.

Updated the vec3 lib, major overhaul.

Posted by on January 25, 2009

The VEC3 lib was updated today, I haven’t had time to put the newer versions as they were developed so I’m just uploading the latest version right now. A small change-log can be found at the header of the source.

Same link as before: VEC3_MACRO.PBI

Or you can download the package: VEC3_MACRO.ZIP