mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-13 09:02:10 +00:00
Changed to const references and added warning
This commit is contained in:
parent
4d820e24aa
commit
20415f4ca2
@ -9,7 +9,7 @@
|
|||||||
#include "strops.h"
|
#include "strops.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
float precedence(char op) {
|
float precedence(const char& op) {
|
||||||
if (op == '+' || op == '-')
|
if (op == '+' || op == '-')
|
||||||
return 1;
|
return 1;
|
||||||
if (op == '*' || op == '/')
|
if (op == '*' || op == '/')
|
||||||
@ -19,20 +19,22 @@ float precedence(char op) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float applyOp(float a, float b, char op) {
|
float applyOp(const float& a, const float& b, const char& op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case '+': return a + b;
|
case '+': return a + b;
|
||||||
case '-': return a - b;
|
case '-': return a - b;
|
||||||
case '*': return a * b;
|
case '*': return a * b;
|
||||||
case '/': return a / b;
|
case '/': return a / b;
|
||||||
case '^': return pow(a, b);
|
case '^': return pow(a, b);
|
||||||
|
default: LogWarning("operator \'" << op << "\' does not exist");
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function that returns value of
|
// Function that returns value of
|
||||||
// expression after evaluation.
|
// expression after evaluation.
|
||||||
float evaluate(string tokens) {
|
float evaluate(const string& t) {
|
||||||
tokens = replace(tokens, " ", "");
|
tokens = replace(t, " ", "");
|
||||||
|
|
||||||
float i;
|
float i;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user