Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2005-07-17 14:42:48


I have now completed a compile time version of double which (as far as
I have been able to test) the same results as the runtime equivalent.

I have implemented mpl-support for all arithmetic operations plus all
comparison operations.
To test the accuracy, I have tested it against Cromwells
sine-implementation (which by the way had a bug: In stead of
1-(angle*angle*/((2*i+2)*(2*i+3))*next_term it had
(angle*angle*/((2*i+2)*(2*i+3))*next_term-1)
and got the same result as a runtime-equivalent implementation of the
same algorithm.

There are four ways to construct a double:
integral_to_double<mpl::int_<-355> > or integral_c_to_double<int,-355>::type
string_c_to_double<3,'.',1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9>
typedef BOOST_DOUBLE(3.141592653589793238462643383279502884197169399375105820974944592)
pi;
double_<mantissa<0x6487ed51,0x085a3000>,1,0> <-Equivalent of pi.

The algorithm behind string_c_to_double is not very efficient, so if
anyone has a better idea for an implementation, feel free to
contribute :)

BOOST_DOUBLE is a non-compliant macro that relies on compile time
behaviour of floating operations.

I have not yet added code to handle +-infinity,QNan,and SNan, but this
is relatively easy.
0.0 is not represented correctly (has wrong exponent when converted to double)
+0.0 does not equal -0.0 yet.

On the upside, this implementation uses a 61 bit mantissa, so it is
possible to utilize the full mantissa without rounding when
calculating e.g. sine.
This is done using
boost::metamath::detail::plus_double_double<a,b>::type
boost::metamath::detail::times_double_double<a,b>::type
boost::metamath::detail::divides_double_double<a,b>::type
The user should then deal with rounding before returning the final value:
boost::metamath::detail::round<a>::type;
or
boost::metamath::detail::cutoff<a>::type;
if no rounding is wanted.

The source is available from the vault:
http://boost-sandbox.sourceforge.net/vault/ <metamath.zip>

Regards,
Peder Holt


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk