Skip to content

forestbelton/fp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fp

fp is an ISO/IEC 9899:1999 (C99) compliant software floating point library. It supports up to 14 decimal digits of precision, utilizing an internal format based on packed BCD. I chose this format to mimic the floating point representation used on the TI-8x line of calculators. This format takes up slightly more (2 bytes) space than an IEEE 754 binary64 type, but it has several advantages:

  • It's easy to read. Since the data is in BCD, you can examine and manipulate the hexadecimal representation easily.
  • It accurately stores common values such as 0.1. This is not possible in base-2 floating point representations.

Associated tools

  • tools/fpp: Preprocessor used to turn %FP(...) or %FP_CONST(...) into an internal representation.
  • tools/fp-calc: Simple REPL used to provide interactive testing of library.

Supported operations

  • Basic arithmetic (+, -, *, /) and comparison
  • Polynomial evaluation using the Horner scheme
  • Conversion operations to/from various data types
  • Arithmetic-geometric mean
  • Exponential functions (exp, pow, log, sqrt) (WIP)

Planned features

  • Basic trigonometric functions (sin, cos, tan)

Build instructions

The only programs required to build this program are gcc, bison and flex. To build and install, all you have to do is

$ make && sudo make install

Example usage

The API is designed for ease of use over efficiency. You can find examples available in the ex directory. If %FP(...) or %FP_CONST(...) is used in your source code for floating-point constants, you need to run your code through the fpp preprocessor before compiling. A sample invocation is given below:

$ fpp mycode.c | gcc -xc - -o mycode

About

A software floating-point library that utilizes BCD.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages