
Boost : 
From: Michael Marcin (mike_at_[hidden])
Date: 20060903 06:21:45
"Michael Marcin" <mmarcin_at_[hidden]> wrote in message
news:<ecg4ib$d6h$1_at_[hidden]>...
> Does boost have a fixedpoint math library?
>
I guess not.
I wrote something to suit my immediate needs.
This is my first try at writing boostlike code.
I'd appreciate suggestions/criticism.
One thing I'd like to do is add optional over/underflow, but I'm not sure
how
I'll do that yet. For another I think I should specialize
std::numeric_limits
for the fixed type, but I'm not sure what to put for a lot of the entries as
I've only ever needed min() and max() myself.
Thanks,
Michael Marcin
Method Solutions, Programmer
// a simple function to instantiate my definitions
void instatiate_fixed()
{
using namespace boostish::math;
typedef fixed<16,16> fx16_16;
fx16_16 testint(5);
fx16_16 testfloat(5.0f);
fx16_16 testdouble(5.0);
fx16_16 test = fx16_16(5); // copy constructions
test = fx16_16(5); // assignment
assert( test < fx16_16(6) ); // less than compare
assert( test == fx16_16(5) ); // equality compare
test += fx16_16(5); // addition and assignment
test = fx16_16(5); // subtraction and assignment
test *= fx16_16(5); // multiplication and assignment
test /= fx16_16(5); // division and assignment
++test; // prefix increment
test; // prefix decrement
test *= 5; // integer multiplication and assignment
test /= 5; // integer division and assignment
test = test * 5; // integer multiplication
test = 5 * test; // commutative integer multiplication
test = test / 25; // integer division
assert( to_integer(test) == 5 ); // conversion to integer
assert( to_float(test) == 5.0f ); // conversion to float
assert( to_double(test) == 5.0 ); // conversion to double
fx16_16 raw = as_fixed( 1<<16 );// raw fixedpoint number to wrapped
fixedpoint
assert( raw == fx16_16(1) );
}
 No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.405 / Virus Database: 268.11.7/436  Release Date: 9/1/2006
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk