
Boost : 
Subject: Re: [boost] Arbitrary precision arithmetic
From: Stephen Nuchia (snuchia_at_[hidden])
Date: 20090818 17:25:28
I had drafted an earlier reply but perhaps I botched sending it as I've
not seen it come through. My opinion then was that this (a bignum
library) is a poor fit for the boost community, considering the amount
and kind of platformspecific microoptimization that goes on in the GMP
library camp.
But today I'm writing unit tests for some tricky floatingpoint
calculation sequences and it occurs to me that a reliable
arbitraryprecision library with a very good API would be just the thing
for calculating the "should be" values. Support for crypto and
calculator demo programs round out the justification.
A bignum library focused primarily on portable, provably correct
"reference implementations" of the algorithms rather than on performance
would have a lot of value.
My toolbag for writing tests like these includes testing properties of
the answers rather than checking their values against predictions,
choosing input data for which the output is easy to calculate, or
writing a model of the calculation in Mathematica, executing it manually
for preselected values, and pasting the answers into an expected value
table.
The way Mathematica answers the questions "what is the value of this
expression, rounded to 53 bits?" is to evaluate the expression using a
heuristically determined amount of extra precision and interval
arithmetic. If both ends of the result interval round to the same
number we have an answer, otherwise the calculation is repeated with
increasing precision until the results converge.
Having just recently taken a look at the boost::proto stuff I think it
might be possible to directly implement this concept with expressions
written in C++. Now that would be a trip!
The boost community is not set up to duplicate what GMP does. But I
think we could do something else very well if we focus on correctness,
portability, and metaprogramming API tastiness instead of making the
tires smoke.
If I grok the proto stuff correctly it should be possible to write
expressions that can be evaluated in different contexts. One could be
native hardware FP arithmetic, one could be the reference bignum
library, and one could even use GMP. Right?
swn
Lambda expressions in a statically typed, compiled language. It's
actually making me giddy!
Selfidentified old fart story: I implemented lambda expressions in C
using a preprocessor in 1987 or 88, while working in the Sun Windows
API. It had a very finegrained callback design and the resulting
namespace pollution and lack of locality when reading code drove me to
it. It actually worked really well for that application.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk