libnum: num abs() and comparison with double
This commit is contained in:
parent
7f104395e0
commit
17e50fc79e
|
@ -134,6 +134,9 @@ struct num8
|
|||
x.v = v;
|
||||
return x;
|
||||
}
|
||||
inline constexpr num8 abs() const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* Comparisons with int */
|
||||
|
||||
|
@ -247,6 +250,11 @@ struct num16
|
|||
x.v = v & 0xff;
|
||||
return x;
|
||||
}
|
||||
inline constexpr num16 abs() const {
|
||||
num16 x;
|
||||
x.v = (v < 0) ? -v : v;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* Comparisons with int */
|
||||
|
||||
|
@ -365,6 +373,11 @@ struct num32
|
|||
x.v = v & 0xffff;
|
||||
return x;
|
||||
}
|
||||
inline constexpr num32 abs() const {
|
||||
num32 x;
|
||||
x.v = (v < 0) ? -v : v;
|
||||
return x;
|
||||
}
|
||||
num32 sqrt() const;
|
||||
|
||||
/* Comparisons with int */
|
||||
|
@ -471,6 +484,11 @@ struct num64
|
|||
x.v = v & 0xffffffffull;
|
||||
return x;
|
||||
}
|
||||
inline constexpr num64 abs() const {
|
||||
num64 x;
|
||||
x.v = (v < 0) ? -v : v;
|
||||
return x;
|
||||
}
|
||||
|
||||
/* Limits as int */
|
||||
static constexpr int minInt = 0;
|
||||
|
@ -621,6 +639,28 @@ inline constexpr T operator/(T const &x, int n) {
|
|||
return r;
|
||||
}
|
||||
|
||||
/* Comparison with double */
|
||||
|
||||
template<typename T> requires(is_num<T>)
|
||||
inline constexpr bool operator<(T const &x, double const &y) {
|
||||
return x < T(y);
|
||||
}
|
||||
|
||||
template<typename T> requires(is_num<T>)
|
||||
inline constexpr bool operator>=(T const &x, double const &y) {
|
||||
return x >= T(y);
|
||||
}
|
||||
|
||||
template<typename T> requires(is_num<T>)
|
||||
inline constexpr bool operator<=(T const &x, double const &y) {
|
||||
return x <= T(y);
|
||||
}
|
||||
|
||||
template<typename T> requires(is_num<T>)
|
||||
inline constexpr bool operator>(T const &x, double const &y) {
|
||||
return x > T(y);
|
||||
}
|
||||
|
||||
/* Other specific operations */
|
||||
|
||||
inline constexpr num32 num16::dmul(num16 const &x, num16 const &y)
|
||||
|
|
Loading…
Reference in New Issue