Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jun 2008 18:04:36 +0000 (UTC)
From:      dfeustel@mindspring.com
To:        Ivan Voras <ivoras@freebsd.org>
Cc:        hackers@freebsd.org
Subject:   Re: Software floating point library?
Message-ID:  <20080628180436.AB2158FC12@mx1.freebsd.org>
In-Reply-To: <9bbcef730806280936y1e669a91t2817ba7ca1de22f3@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jun 28, 2008 at 06:36:34PM +0200, Ivan Voras wrote:
> Does anyone know of a simple, BSD (or compatible) licensed software
> math library that emulates floating point numbers? Ideally, it should
> be a single .c file library that implements basic operations (+, -, *,
> /, negation, comparisons, convert to/from machine integers and
> strings), that uses a standard C type (int or long long) to store the
> value, and is usable in the kernel.
> 
> Alternatively, how about a fixed-point library with the same
> properties? (I know it's easy to do, but don't want to reinvent the
> wheel again if I don't have to).
> 

If you don't mind having unlimited precision, check out the math library
used in the calc program from isthe.com.

        USING THE ARBITRARY PRECISION ROUTINES IN A C PROGRAM

Part of the calc release consists of an arbitrary precision math link
library.  This link library is used by the calc program to perform its
own calculations.  If you wish, you can ignore the calc program entirely
and call the arbitrary precision math routines from your own C programs.

The link library is called libcalc.a, and provides routines to handle
arbitrary precision arithmetic with integers, rational numbers, or
complex numbers.  There are also many numeric functions such as
factorial and gcd, along with some transcendental functions such as sin
and exp.

Take a look at the sample sub-directory.  It contains a few simple
examples of how to use libcalc.a that might be helpful to look at after
you have read this file.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080628180436.AB2158FC12>