feat: added isSmall test for vec, and more compere function in decimals
This commit is contained in:
14
fastmath.hpp
14
fastmath.hpp
@@ -55,6 +55,12 @@ struct decimal {
|
|||||||
friend bool operator>(const decimal &d1, const decimal &d2) {
|
friend bool operator>(const decimal &d1, const decimal &d2) {
|
||||||
return d1.i > d2.i;
|
return d1.i > d2.i;
|
||||||
}
|
}
|
||||||
|
friend bool operator<=(const decimal &d1, const decimal &d2) {
|
||||||
|
return d1.i <= d2.i;
|
||||||
|
}
|
||||||
|
friend bool operator>=(const decimal &d1, const decimal &d2) {
|
||||||
|
return d1.i >= d2.i;
|
||||||
|
}
|
||||||
|
|
||||||
friend bool operator==(const decimal &d1, const decimal &d2) {
|
friend bool operator==(const decimal &d1, const decimal &d2) {
|
||||||
return d1.i == d2.i;
|
return d1.i == d2.i;
|
||||||
@@ -62,7 +68,6 @@ struct decimal {
|
|||||||
friend bool operator!=(const decimal &d1, const decimal &d2) {
|
friend bool operator!=(const decimal &d1, const decimal &d2) {
|
||||||
return d1.i != d2.i;
|
return d1.i != d2.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
decimal &operator=(decimal const &in) {
|
decimal &operator=(decimal const &in) {
|
||||||
if (this != &in) {
|
if (this != &in) {
|
||||||
std::destroy_at(this);
|
std::destroy_at(this);
|
||||||
@@ -155,6 +160,13 @@ template <int n, class Dev> struct vec {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
bool isSmall() {
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (abs(v[i].i) > (1 << (HALF_SHIFT - 1)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
decimal &operator[](const int &i) { return v[i]; }
|
decimal &operator[](const int &i) { return v[i]; }
|
||||||
|
|
||||||
decimal len_sq() { return *this * *this; }
|
decimal len_sq() { return *this * *this; }
|
||||||
|
|||||||
Reference in New Issue
Block a user