Added a bunch of functions.

This commit is contained in:
brad Arant committed 2025-11-08 20:04:45 -08:00
1 parent 96302e1d27
commit c4f0fab8c7
9 files changed
+423 -18

No files matched your search

+137 -11
View File
@@ -2,8 +2,10 @@
#include "Exception.h"
#include <format>
#include <iostream>
#include <algorithm>
#include <time.h>
#include <chrono>
#include <cmath>
namespace jet {
@@ -116,7 +118,16 @@ namespace jet {
} else
throw coreutils::Exception("Expecting ) at end of INTEGER expression.");
} else if(in.ifNextIgnoreCase("ROUND")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for ROUND parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = round(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of ROUND expression.");
} else if(in.ifNextIgnoreCase("RANDOM")) {
unsigned int seed = (unsigned int)clock();
doubleValue = (double) rand_r(&seed) / (RAND_MAX + 1.0);
@@ -124,29 +135,144 @@ namespace jet {
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else if(in.ifNextIgnoreCase("ABS")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for ABS parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = abs(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of ABS expression.");
} else if(in.ifNextIgnoreCase("MAX")) {
} else if(in.ifNextIgnoreCase("MIN")) {
} else if(in.ifNextIgnoreCase("POW")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for POW parameters.");
Operand parm1(in, tag);
if(!in.ifNext(","))
throw coreutils::Exception("Expecting , in POW expression.");
Operand parm2(in, tag);
if(in.ifNext(")")) {
doubleValue = pow(parm1.doubleValue, parm2.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of substring expression.");
} else if(in.ifNextIgnoreCase("SIN")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for SIN parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = sin(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of SIN expression.");
} else if(in.ifNextIgnoreCase("ASIN")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for ASIN parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = asin(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of ASIN expression.");
} else if(in.ifNextIgnoreCase("COS")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for COS parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = cos(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of COS expression.");
} else if(in.ifNextIgnoreCase("ACOS")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for ACOS parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = acos(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of ACOS expression.");
} else if(in.ifNextIgnoreCase("ATAN")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for ATAN parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = atan(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of ATAN expression.");
} else if(in.ifNextIgnoreCase("SQRT")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for SQRT parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = sqrt(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of SQRT expression.");
} else if(in.ifNextIgnoreCase("DEG")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for DEG parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = parm1.doubleValue * 180 / 3.14159;
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of DEG expression.");
} else if(in.ifNextIgnoreCase("RAD")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for RAD parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = parm1.doubleValue * 3.14159 / 180;
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of RAD expression.");
} else if(in.ifNextIgnoreCase("TAN")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for TAN parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = tan(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of TAN expression.");
} else if(in.ifNextIgnoreCase("TRUNC")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for TRUNC parameters.");
Operand parm1(in, tag);
if(in.ifNext(")")) {
doubleValue = trunc(parm1.doubleValue);
isNumber = true;
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("Expecting ) at end of TRUNC expression.");
} else if(in.ifNextIgnoreCase("CEIL")) {
} else if(in.ifNextIgnoreCase("FLOOR")) {