1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <blitz/array.h>
#include <blitz/numinquire.h>
using namespace blitz;
// A simple fixed point arithmetic class which represents a point
// in the interval [0,1].
class FixedPoint {
public:
typedef unsigned int T_mantissa;
FixedPoint() { }
FixedPoint(T_mantissa mantissa)
{
mantissa_ = mantissa;
}
FixedPoint(double value)
{
assert((value >= 0.0) && (value <= 1.0));
mantissa_ = value * huge(T_mantissa());
}
FixedPoint operator+(FixedPoint x)
{ return FixedPoint(mantissa_ + x.mantissa_); }
double value() const
{ return mantissa_ / double(huge(T_mantissa())); }
private:
T_mantissa mantissa_;
};
ostream& operator<<(ostream& os, const FixedPoint& a)
{
os << a.value();
return os;
}
int main()
{
// Create an array using the FixedPoint class:
Array<FixedPoint, 2> A(4,4), B(4,4);
A = 0.5, 0.3, 0.8, 0.2,
0.1, 0.3, 0.2, 0.9,
0.0, 1.0, 0.7, 0.4,
0.2, 0.3, 0.8, 0.4;
B = A + 0.05;
cout << "B = " << B << endl;
return 0;
}
|