|
|
@ -3,16 +3,15 @@
|
|
|
|
#include "operators.hpp"
|
|
|
|
#include "operators.hpp"
|
|
|
|
#include "../variables/value.hpp"
|
|
|
|
#include "../variables/value.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Now replace every single operation with vector equivalent
|
|
|
|
// NOTE: Value* x is what is going to be returned for operations, so that we avoid the need for allocating more memory
|
|
|
|
|
|
|
|
|
|
|
|
Value* add(Value* x, Value* y) {
|
|
|
|
Value* add(Value* x,Value* y) {
|
|
|
|
if (!x || !y) { std::cerr << "Error, uninitialized values being used in add." << std::endl; }
|
|
|
|
if (!x || !y) { std::cerr << "Error, uninitialized values being used in add." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot add a boolean." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot add a boolean." << std::endl; }
|
|
|
|
if ((x->type == STRING || y->type == STRING) && (x->type != STRING || y->type != STRING)) {
|
|
|
|
if ((x->type == STRING || y->type == STRING) && (x->type != STRING || y->type != STRING)) {
|
|
|
|
std::cerr << "Error, cannot add a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot add a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
|
|
|
|
|
|
|
@ -23,36 +22,35 @@ Value* add(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::plus<long>());
|
|
|
|
std::back_inserter(longResult), std::plus<long>());
|
|
|
|
ans = make_long(longResult);
|
|
|
|
set_long(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::plus<>());
|
|
|
|
std::back_inserter(doubleResult), std::plus<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::plus<>());
|
|
|
|
std::back_inserter(doubleResult), std::plus<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_string(get_string(x) + get_string(y));
|
|
|
|
set_string(x, get_string(x) + get_string(y));
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::plus<double>());
|
|
|
|
std::back_inserter(doubleResult), std::plus<double>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* subtract(Value* x, Value* y) {
|
|
|
|
Value* subtract(Value* x, Value* y) {
|
|
|
@ -60,7 +58,6 @@ Value* subtract(Value* x, Value* y) {
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot subtract a boolean." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot subtract a boolean." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot subtract a string." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot subtract a string." << std::endl; }
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
|
|
|
|
|
|
|
@ -71,34 +68,33 @@ Value* subtract(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::minus<long>());
|
|
|
|
std::back_inserter(longResult), std::minus<long>());
|
|
|
|
ans = make_long(longResult);
|
|
|
|
set_long(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::minus<>());
|
|
|
|
std::back_inserter(doubleResult), std::minus<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::minus<>());
|
|
|
|
std::back_inserter(doubleResult), std::minus<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::minus<double>());
|
|
|
|
std::back_inserter(doubleResult), std::minus<double>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* division(Value* x, Value* y) {
|
|
|
|
Value* division(Value* x, Value* y) {
|
|
|
@ -106,7 +102,6 @@ Value* division(Value* x, Value* y) {
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot divide a boolean." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot divide a boolean." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot division a string." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot division a string." << std::endl; }
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
|
|
|
|
|
|
|
@ -117,34 +112,33 @@ Value* division(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::divides<long>());
|
|
|
|
std::back_inserter(longResult), std::divides<long>());
|
|
|
|
ans = make_long(longResult);
|
|
|
|
set_long(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::divides<>());
|
|
|
|
std::back_inserter(doubleResult), std::divides<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::divides<>());
|
|
|
|
std::back_inserter(doubleResult), std::divides<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::divides<double>());
|
|
|
|
std::back_inserter(doubleResult), std::divides<double>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* multiplication(Value* x, Value* y) {
|
|
|
|
Value* multiplication(Value* x, Value* y) {
|
|
|
@ -152,7 +146,6 @@ Value* multiplication(Value* x, Value* y) {
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot multiply a boolean." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot multiply a boolean." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot multiply a string." << std::endl; }
|
|
|
|
if (x->type == STRING || y->type == STRING) { std::cerr << "Error, cannot multiply a string." << std::endl; }
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
std::vector<double> doubleResult;
|
|
|
|
|
|
|
|
|
|
|
@ -163,34 +156,33 @@ Value* multiplication(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::multiplies<long>());
|
|
|
|
std::back_inserter(longResult), std::multiplies<long>());
|
|
|
|
ans = make_long(longResult);
|
|
|
|
set_long(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
doubleResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<>());
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<>());
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
doubleResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<double>());
|
|
|
|
std::back_inserter(doubleResult), std::multiplies<double>());
|
|
|
|
ans = make_double(doubleResult);
|
|
|
|
set_double(x, doubleResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* less(Value* x, Value* y) {
|
|
|
|
Value* less(Value* x, Value* y) {
|
|
|
@ -200,7 +192,6 @@ Value* less(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -210,38 +201,39 @@ Value* less(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::less<long>());
|
|
|
|
std::back_inserter(longResult), std::less<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::less<>());
|
|
|
|
std::back_inserter(longResult), std::less<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::less<>());
|
|
|
|
std::back_inserter(longResult), std::less<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) < 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) < 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::less<double>());
|
|
|
|
std::back_inserter(longResult), std::less<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CONTINUE REPLACING FROM HERE
|
|
|
|
|
|
|
|
|
|
|
|
Value* greater(Value* x, Value* y) {
|
|
|
|
Value* greater(Value* x, Value* y) {
|
|
|
|
if (!x || !y) { std::cerr << "Error, uninitialized values being used in greater." << std::endl; }
|
|
|
|
if (!x || !y) { std::cerr << "Error, uninitialized values being used in greater." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot numerically compare a boolean." << std::endl; }
|
|
|
|
if (x->type == BOOLEAN || y->type == BOOLEAN) { std::cerr << "Error, cannot numerically compare a boolean." << std::endl; }
|
|
|
@ -249,7 +241,6 @@ Value* greater(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -259,36 +250,35 @@ Value* greater(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater<long>());
|
|
|
|
std::back_inserter(longResult), std::greater<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater<>());
|
|
|
|
std::back_inserter(longResult), std::greater<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater<>());
|
|
|
|
std::back_inserter(longResult), std::greater<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) > 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) > 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater<double>());
|
|
|
|
std::back_inserter(longResult), std::greater<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* less_equal(Value* x, Value* y) {
|
|
|
|
Value* less_equal(Value* x, Value* y) {
|
|
|
@ -298,7 +288,6 @@ Value* less_equal(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -308,36 +297,35 @@ Value* less_equal(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::less_equal<long>());
|
|
|
|
std::back_inserter(longResult), std::less_equal<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_long(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::less_equal<>());
|
|
|
|
std::back_inserter(longResult), std::less_equal<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::less_equal<>());
|
|
|
|
std::back_inserter(longResult), std::less_equal<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) <= 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) <= 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::less_equal<double>());
|
|
|
|
std::back_inserter(longResult), std::less_equal<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* greater_equal(Value* x, Value* y) {
|
|
|
|
Value* greater_equal(Value* x, Value* y) {
|
|
|
@ -347,7 +335,6 @@ Value* greater_equal(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -357,36 +344,35 @@ Value* greater_equal(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater_equal<long>());
|
|
|
|
std::back_inserter(longResult), std::greater_equal<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater_equal<>());
|
|
|
|
std::back_inserter(longResult), std::greater_equal<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater_equal<>());
|
|
|
|
std::back_inserter(longResult), std::greater_equal<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) >= 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) >= 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::greater_equal<double>());
|
|
|
|
std::back_inserter(longResult), std::greater_equal<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* equals(Value* x, Value* y) {
|
|
|
|
Value* equals(Value* x, Value* y) {
|
|
|
@ -395,7 +381,6 @@ Value* equals(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans = nullptr;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -405,36 +390,35 @@ Value* equals(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::equal_to<long>());
|
|
|
|
std::back_inserter(longResult), std::equal_to<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::equal_to<>());
|
|
|
|
std::back_inserter(longResult), std::equal_to<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::equal_to<>());
|
|
|
|
std::back_inserter(longResult), std::equal_to<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) == 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) == 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::equal_to<double>());
|
|
|
|
std::back_inserter(longResult), std::equal_to<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* not_equals(Value* x, Value* y) {
|
|
|
|
Value* not_equals(Value* x, Value* y) {
|
|
|
@ -443,7 +427,6 @@ Value* not_equals(Value* x, Value* y) {
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
std::cerr << "Error, cannot compare a string with another data type." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* ans= nullptr;
|
|
|
|
|
|
|
|
std::vector<long> longResult;
|
|
|
|
std::vector<long> longResult;
|
|
|
|
|
|
|
|
|
|
|
|
// Destruct all four cases
|
|
|
|
// Destruct all four cases
|
|
|
@ -453,36 +436,35 @@ Value* not_equals(Value* x, Value* y) {
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<long>());
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<long>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
} else if (x->type == LONG && y->type == DOUBLE) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
longResult.reserve(x_long.size());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<>());
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
} else if (x->type == DOUBLE && y->type == LONG) {
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
std::vector<long> y_long = get_long(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<>());
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
} else if (x->type == STRING && y->type == STRING) {
|
|
|
|
ans = make_boolean(get_string(x).compare(get_string(y)) != 0);
|
|
|
|
set_boolean(x, get_string(x).compare(get_string(y)) != 0);
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
} else { // Both are DOUBLE
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> x_double = get_double(x);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
std::vector<double> y_double = get_double(y);
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
longResult.reserve(x_double.size());
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::transform(x_double.begin(), x_double.end(), y_double.begin(),
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<double>());
|
|
|
|
std::back_inserter(longResult), std::not_equal_to<double>());
|
|
|
|
ans = make_booleans(longResult);
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return ans;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* and_value(Value* x, Value* y) {
|
|
|
|
Value* and_value(Value* x, Value* y) {
|
|
|
@ -495,10 +477,11 @@ Value* and_value(Value* x, Value* y) {
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::logical_and<>());
|
|
|
|
std::back_inserter(longResult), std::logical_and<>());
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return make_booleans(longResult);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* or_value(Value* x, Value* y) {
|
|
|
|
Value* or_value(Value* x, Value* y) {
|
|
|
@ -511,10 +494,11 @@ Value* or_value(Value* x, Value* y) {
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::transform(x_long.begin(), x_long.end(), y_long.begin(),
|
|
|
|
std::back_inserter(longResult), std::logical_or<>());
|
|
|
|
std::back_inserter(longResult), std::logical_or<>());
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
|
|
|
|
|
|
|
|
delete y;
|
|
|
|
delete y;
|
|
|
|
|
|
|
|
|
|
|
|
return make_booleans(longResult);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Value* not_value(Value* x) {
|
|
|
|
Value* not_value(Value* x) {
|
|
|
@ -525,7 +509,7 @@ Value* not_value(Value* x) {
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::vector<long> x_long = get_long(x);
|
|
|
|
std::transform(x_long.begin(), x_long.end(), std::back_inserter(longResult), std::logical_not<>());
|
|
|
|
std::transform(x_long.begin(), x_long.end(), std::back_inserter(longResult), std::logical_not<>());
|
|
|
|
|
|
|
|
|
|
|
|
delete x;
|
|
|
|
set_booleans(x, longResult);
|
|
|
|
|
|
|
|
|
|
|
|
return make_booleans(longResult);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|