117 return a > b ? 1.0 : 0.0;
130 return a < b ? 1.0 : 0.0;
143 return a == b ? 1.0 : 0.0;
156 return a >= b ? 1.0 : 0.0;
169 return a <= b ? 1.0 : 0.0;
182 return a != b ? 1.0 : 0.0;
229 return (a > 0) ? (int)(a + 0.5) : (int)(a - 0.5);
281 if (isnan(a))
return (a);
282 if (isnan(b))
return (b);
283 return (a > b) ? a : b;
295 if (isnan(a))
return (a);
296 if (isnan(b))
return (b);
297 return (a < b) ? a : b;
302 Calculator::Calculator() {
309 Calculator::~Calculator() {
320 void Calculator::Negative() {
322 PerformOperation(result, result.begin(), result.end(),
NegateOperator);
330 void Calculator::Multiply() {
335 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
MultiplyOperator);
343 void Calculator::Add() {
347 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
AddOperator);
355 void Calculator::Subtract() {
359 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
SubtractOperator);
367 void Calculator::Divide() {
372 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
DivideOperator);
379 void Calculator::Modulus() {
384 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
ModulusOperator);
395 void Calculator::Exponent() {
400 PerformOperation(result, x.begin(), x.end(), exponent.begin(), exponent.end(), pow);
410 void Calculator::SquareRoot() {
412 PerformOperation(result, result.begin(), result.end(), sqrt);
420 void Calculator::AbsoluteValue() {
422 PerformOperation(result, result.begin(), result.end(), fabs);
432 void Calculator::Log() {
434 PerformOperation(result, result.begin(), result.end(), log);
442 void Calculator::Log10() {
444 PerformOperation(result, result.begin(), result.end(), log10);
454 void Calculator::LeftShift() {
457 IString msg =
"When trying to do a left shift calculation, a non-scalar "
458 "shift value was encountered. Shifting requires scalars.";
464 if((
int)y[0] > (
int)x.size()) {
465 IString msg =
"When trying to do a left shift calculation, a shift "
466 "value greater than the data size was encountered. "
467 "Shifting by this value would erase all of the data.";
472 int shift = (int)y[0];
473 result.resize(x.size());
475 for(
int i = 0; i < result.size(); i++) {
476 if(i + shift < x.size() && i + shift >= 0)
477 result[i] = x[i+shift];
479 result[i] = sqrt(-1.0);
493 void Calculator::RightShift() {
496 IString msg =
"When trying to do a right shift calculation, a non-scalar "
497 "shift value was encountered. Shifting requires scalars.";
503 if((
int)y[0] > (
int)x.size()) {
504 IString msg =
"When trying to do a right shift calculation, a shift "
505 "value greater than the data size was encountered. "
506 "Shifting by this value would erase all of the data.";
511 int shift = (int)y[0];
512 result.resize(x.size());
514 for(
int i = 0; i < (int)result.size(); i++) {
515 if(i - shift < (
int)x.size() && i - shift >= 0) {
516 result[i] = x[i-shift];
519 result[i] = sqrt(-1.0);
531 void Calculator::MinimumLine() {
534 double minVal = result[0];
535 for(
int i = 0; i < result.size(); i++) {
537 minVal = min(minVal, result[i]);
542 result.push_back(minVal);
550 void Calculator::MaximumLine() {
553 double maxVal = result[0];
554 for(
int i = 0; i < result.size(); i++) {
556 maxVal = max(maxVal, result[i]);
561 result.push_back(maxVal);
570 void Calculator::MinimumPixel() {
575 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
585 void Calculator::MaximumPixel() {
590 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
600 void Calculator::GreaterThan() {
605 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
615 void Calculator::LessThan() {
620 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
630 void Calculator::Equal() {
635 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
645 void Calculator::GreaterThanOrEqual() {
650 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
660 void Calculator::LessThanOrEqual() {
665 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
675 void Calculator::NotEqual() {
680 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
692 void Calculator::And() {
697 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
706 void Calculator::Or() {
711 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(),
720 void Calculator::Sine() {
722 PerformOperation(result, result.begin(), result.end(), sin);
730 void Calculator::Cosine() {
732 PerformOperation(result, result.begin(), result.end(), cos);
740 void Calculator::Tangent() {
742 PerformOperation(result, result.begin(), result.end(), tan);
750 void Calculator::Cosecant() {
760 void Calculator::Secant() {
762 PerformOperation(result, result.begin(), result.end(),
SecantOperator);
770 void Calculator::Cotangent() {
780 void Calculator::Arcsine() {
782 PerformOperation(result, result.begin(), result.end(), asin);
790 void Calculator::Arccosine() {
792 PerformOperation(result, result.begin(), result.end(), acos);
800 void Calculator::Arctangent() {
802 PerformOperation(result, result.begin(), result.end(), atan);
810 void Calculator::ArcsineH() {
812 PerformOperation(result, result.begin(), result.end(), asinh);
820 void Calculator::ArccosineH() {
822 PerformOperation(result, result.begin(), result.end(), acosh);
830 void Calculator::ArctangentH() {
832 PerformOperation(result, result.begin(), result.end(), atanh);
840 void Calculator::Arctangent2() {
845 PerformOperation(result, x.begin(), x.end(), y.begin(), y.end(), atan2);
853 void Calculator::SineH() {
855 PerformOperation(result, result.begin(), result.end(), sinh);
863 void Calculator::CosineH() {
865 PerformOperation(result, result.begin(), result.end(), cosh);
873 void Calculator::TangentH() {
875 PerformOperation(result, result.begin(), result.end(), tanh);
883 int Calculator::StackSize() {
884 return p_valStack->size();
893 p_valStack->push(vect);
902 void Calculator::Push(
double scalar) {
917 for(
int i = 0; i < buff.
size(); i++) {
961 if(p_valStack->empty()) {
962 IString msg =
"Math calculator stack is empty, cannot perform any "
967 top = p_valStack->top();
970 for(
int i = 0; i < (int)top.size(); i++) {
975 else if(top[i] > DBL_MAX) {
979 else if(top[i] < -DBL_MAX) {
998 void Calculator::PrintTop() {
999 if(p_valStack->empty())
return;
1003 for(
int i = 0; i < (int)top.size(); i++) {
1004 std::cout << top[i] <<
" ";
1006 std::cout <<
"]" << std::endl;
1015 bool Calculator::Empty() {
1016 return p_valStack->empty();
1023 void Calculator::Clear() {
1024 while(!p_valStack->empty()) {
1042 double operation(
double)) {
1043 results.resize(arg1End - arg1Start);
1045 for(
int pos = 0; pos < results.size(); pos++) {
1046 results[pos] = operation(*arg1Start);
1073 double operation(
double,
double)) {
1074 if(arg1End - arg1Start != 1 && arg2End - arg2Start != 1 &&
1075 arg1End - arg1Start != arg2End - arg2Start) {
1076 IString msg =
"The stack based calculator cannot operate on vectors "
1077 "of differing sizes.";
1081 int iSize = max(arg1End - arg1Start, arg2End - arg2Start);
1082 results.resize(iSize);
1084 for(
int pos = 0; pos < results.size(); pos++) {
1085 results[pos] = operation(*arg1Start, *arg2Start);
1087 if(arg1Start + 1 != arg1End) arg1Start++;
1088 if(arg2Start + 1 != arg2End) arg2Start++;