Floating point library for PIC micro controllers

PICFLOAT is a open source floating point library for midrange PIC processors from Microchip.

Language Used: PIC Assembler
Note: the test utilities and utilities for creating floating point numbers are in C

Tools Needed: GPASM or MPASM, GCC and Make

License: BSD

Format: IEEE 32bit single and 40bit format (8bit signed exponent,32bit mantissa, 1bit sign - calculations are done in 40bit format including trig,log, etc)

Main features:
 - small size - all of it - and testing code fits inside 2K code!
 - heavy use of macros (over 300) makes code readable and portable
 - only assume one 8bit register called W (easy to change) - and limited use of an  index register
 - testing is done with paranoia math test suite

Target PIC Processors: 14bit processors (initial port)

Support Utilities:  Includes programs to generate tables or constants from floating point numbers that can be included in assembler code

Testing of core math function:
I have run this code against the PARANOIA test suite by Steve Moshier using a modified version of the PIC simulator PSIM by Eric Smith
See support links

Macros: define all core multibyte functions (1 to N byte size!) to make building function easy; such as:
-Arithmetic, Logical, Shifts, Compares, Load (Direct and Constant), Store, Bit Operations, Looping, Increment, Decrement, Jumps
Macros are also used to invoke all function calls (for readability and mainly to allow modification of calling methods on various PICs)
32bit math:  32bit integer functions based on macro headers including Multiply, Divide, Conversions to/from 8, 16, 24 and 32bit signed/unsigned values
I/O: 32bit BCD: convert up to 32bit numbers to BCD and output results in ASCII, ATOI convert ASCII to 32bit
Floating point core:  Conversions (IEEE to/from 40bit temporary real) Load/Store ( to/from IEEE or 40bit temporary real)  Arithmetic, Increment, Decrement,
Conversions (to/from 8, 16, 24, 32bit integers signed/unsigned)
Floating point functions: Poly, Sqrt, Sin, Cos, Tan, Asin, Acos, Atan, Log, Exp, Pow, Test (Zero/Nonzero), Split(Real,Integer), Floor, Ceil, LDEXP, FREXP, FMOD, INVERT(1/X)
Floating Point I/O: FTOA - Binary to ASCII floating and  ATOF ASCII to floating conversions supporting scientific notation
Table functions:  32bit math, 40 and 32bit Floating point load
Memory functions: memory copy


I started working on this project back in 1990. I started with a macro library to make using the PIC easier to use. I felt that having a generic base of multi-byte functions would allow making math libraries mush easier to do. I had the floating point core written in 1991. The project was revisited over the years to include most of the common C floating point math functions. I had planned to have the library as part of an interpreter with the higher level functions and data kept in NVRAM. This has much to do with why there is no banking code in this project (It would be easy to have this code and a small interpreter fit inside of 2K code if many of the functions were moved to NVRAM)

Wish List:
I hope others can work on and expand on this project. Some ideas for areas improvement could be

I believe that prior to this project that PIC assembler support for floating point functions, and good macro support in general, has been seriously lacking.
Keep in mind the limited numeric resolution resulting from the number formats themselves when doing computations! Take a small number, say delta, and add another number that is larger in magnitude by 2**(bits of precision) - the delta contribution is lost.. A good example of this problem occurs when passing two angles near 90 degrees that differ by a small ammont - if you are depending on measuring small changes in these angles your results will  have large unexpected errors - so take time to understand this limit and rework your computations as required. No amount of design given to a mathematical functions can compensate from being badly used. (But please feel free to fix any bugs you may find in my code 8-)

If anyone is interested in tools to make interpreters I would suggest using the COCOR compiler construction toolset by Frankie Arzu
- comes with easy to use examples

Please feel free to contribute code ideas and suggestions to this project!

Mike Gore
Source Forge Project Page and Downloads
Source Forge Project CVS Page
Mailing List

Support Links: PARANOIA - Steve Moshiers home page
PSIM  Source Forge
GPUTILS - Source Forge

This Site Hosted by



Last updated: 4 Jan 2004