This is a first attempt at this. An algebra has been implemented which seemed sensible to the authors. However this may not seem sensible to you, therefore please let us know if this is the case. The subtlety comes in defining the difference between such cyclic values.
The Phi calss provided here performs cyclic algebra in the range [ -Pi, Pi ]
The main constructor takes a double argument of any value. This is shifted by as many multiples of 2Pi as neccessary to put it into the defined range.
All arithmetic operations can take either a Phi or a double on the rhs.
If a double is supplied then it is first converted to a Phi (via the constructor)
and the operation takes place as if both operands were a Phi. In other
words:
Phi
a(1.0), b(2.0), c, d ;
c
= a + b ;
d
= a + 2.0 ;
leaves both c and d being identical.
Similarly the Phi class is convertable to a double, thus the user may
assign:
Phi
phi(1.2) ;
double
val = phi ;
at which point val contains 1.2
The difference between any two Phi objects is somewhat tricky. I has
been defined in this class in the following way:
The magnitude of the result is always the smallest
angle between operands on a polar diagram (<=Pi)
The sign is defined as + if the smallest angle is
obtained going anti-clockwise from 1st operand to 2nd
The sign is defined as -if the smallest angle is
obtained going clockwise from 1st operand to 2nd
Include file : "AtlfastCode/Phi.h"
Source code: in .h file
Constructors | |
Phi ( ) | Creates a Phi with value 0.0 |
Phi( double init ) | Creates a Phi with value = init |
Phi( Phi& ) | Copy constructor |
Arithmetic operations supported | |
operator= | Straightforward assignment |
operator+ | Straightforward addition |
operator- | Subtraction (see description above) |
operator+= | |
operator-= | |
Boolean operations | |
operator< | Less than comparison
Implemented naively according to strict ordering in range -Pi->Pi |
operator> | Greater than comparison (see <) |
Conversions | |
operator double() | Conversion to a double. |