fixed.cpp | fixed.cpp | |||
---|---|---|---|---|
#include <blitz/array.h> | ||||
#include <blitz/numinquire.h> | ||||
using namespace blitz; | #include <fixed-point.h> // FixedPoint class | |||
// 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() | int main() | |||
{ | { | |||
// Create an array using the FixedPoint class: | // Create an array using the FixedPoint class: | |||
Array<FixedPoint, 2> A(4,4), B(4,4); | Array<FixedPoint, 2> A(4,4), B(4,4); | |||
A = 0.5, 0.3, 0.8, 0.2, | A = 0.5, 0.3, 0.8, 0.2, | |||
0.1, 0.3, 0.2, 0.9, | 0.1, 0.3, 0.2, 0.9, | |||
0.0, 1.0, 0.7, 0.4, | 0.0, 1.0, 0.7, 0.4, | |||
End of changes. 2 change blocks. | ||||
39 lines changed or deleted | 1 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |