Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-08 08:31:31


Peder Holt <peder.holt_at_[hidden]> writes:

> Is there any interest in a compile-time meta-version of double?
>
> Syntax:
>
> //Definition
> typedef META_DOUBLE(3.1415926535897932384626433) pi;
> //Or
> META_DOUBLE(3.1415926535897932384626433) pi_;

Whoa, that's nice syntax!

I'm still trying to guess how you do it. Does the PP treat 3.14 as
three tokens?

> //Mathematical operations
> typedef math::meta::add<pi,pi>::type pi2;
>
> //Evaluation:
> assert(META_DOUBLE_EVAL(pi2)==3.1415926535897932384626433*2);

Really, even with FP rounding errors? I guess multiplying by 2 is
fairly safe...

> This implementation uses two ints to represent the decimals, and a
> short to represent the exponent.

I don't understand why you'd choose int for one and short for the
other when they have the same range requirements: both int and short
are required to be at least 16 bits and neither short nor int is
required to be more than 16 bits. Can you explain that?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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