October 26, 2016
Hot Topics:

Understanding Floating Point Math Under Palm OS

  • March 11, 2005
  • By Alex Gusev
  • Send Email »
  • More Articles »

Performing Standard Operations on Floating Numbers

Software Floating Point Emulator(sfpe) under Palm OS keeps status of floating operations. You can obtain and set it by calling the following functions:

 * Constants passed to _fp_set_fpscr and received from
 * _fp_get_fpscr are:
 *   flpInvalid, flpOverflow, flpUnderflow, flpDivByZero,
 *   or flpInexact

Int32  _fp_get_fpscr(void)
void   _fp_set_fpscr(Int32)

That is a good way to check for errors; for example, division by zero or overflow. Additional explanations on what IEEE floating point errors are can be found, for instance, here at Sun's site.

Float Manager offers a long list of functions used for various conversions between numeric types, comparisons, and basic calculations. For conversions, you will find the following comment in FloatMgr.h:

 * The shorthand here can be determined from the context:
 *  i    --> long (Int32)
 *  u    --> UInt32 (UInt32)
 *  ll   --> long long int
 *  ull  --> UInt32 long int
 *  f    --> float
 *  d    --> double
 *  q    --> long double (defaults to double in this implementaton)
 *  XtoY --> map of type X to a value of type Y

so you will convert something like a UInt32 value to a double by calling:

UInt32 nUInt32Val = 10;
FlpDouble dblVal = _d_utod(nUInt32Val);

A similar block of functions exists for floating point numbers' comparions. I'd like to point out one interesting fact here. Most comparison functions can be defined in the form of _T_Tcmp[e], where T is the argument type. '[e]' versions set a flpInvalid flag in the fpscr register when the operands are unordered. It happens if they have no numerical relationship; in other words, when one or both of them are not numbers, such as with NaN. So, a common rule for comparison functions will be:

/* _T_Tcmp[e]
 * The function shorthand is:
 *  eq  --> equal
 *  ne  --> not equal
 *  lt  --> less than
 *  le  --> less than or equal to
 *  gt  --> greater than
 *  ge  --> greater than or equal to
 *  un  --> unordered with
 *  or  --> ordered with (i.e. less than, equal to, or greater than)

The rest of the add/sub/mul/div functions are trivial enough that they should not require an explanation.


Floating point math is one of the shortcomings with Palm OS. It is getting better with new versions of the OS, so who knows; maybe soon you'll be able to the use standard C library and forget about all that was written above.

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers' lives in the mobile jungles a little bit simpler.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel