From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 28 18:04:37 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 091FE106564A for ; Sat, 28 Jun 2008 18:04:37 +0000 (UTC) (envelope-from davidfeustel@comcast.net) Received: from QMTA06.westchester.pa.mail.comcast.net (qmta06.westchester.pa.mail.comcast.net [76.96.62.56]) by mx1.freebsd.org (Postfix) with ESMTP id AB2158FC12 for ; Sat, 28 Jun 2008 18:04:36 +0000 (UTC) (envelope-from davidfeustel@comcast.net) Received: from OMTA09.westchester.pa.mail.comcast.net ([76.96.62.20]) by QMTA06.westchester.pa.mail.comcast.net with comcast id jSKa1Z0010SCNGk560Cd00; Sat, 28 Jun 2008 17:48:35 +0000 Received: from localhost ([69.245.196.200]) by OMTA09.westchester.pa.mail.comcast.net with comcast id jVoU1Z00K4KuD453VVoVmF; Sat, 28 Jun 2008 17:48:29 +0000 X-Authority-Analysis: v=1.0 c=1 a=rGOKwc2IkUQA:10 a=7RRE4XQAWVsA:10 a=fymza44dLP4c43hyBtIA:9 a=1FEhHJUGN-mPXE51PO8A:7 a=6VUSIoP2hIlQ1Caaw1Wq0epT5UIA:4 a=mfJYqndlP_8A:10 a=LY0hPdMaydYA:10 From: dfeustel@mindspring.com To: Ivan Voras In-Reply-To: <9bbcef730806280936y1e669a91t2817ba7ca1de22f3@mail.gmail.com> Message-Id: <20080628180436.AB2158FC12@mx1.freebsd.org> Date: Sat, 28 Jun 2008 18:04:36 +0000 (UTC) Cc: hackers@freebsd.org Subject: Re: Software floating point library? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jun 2008 18:04:37 -0000 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.