23template<
typename T,
int S>
struct UIntF {
24 static_assert(std::is_unsigned_v<T>);
25 static_assert(S >= 1);
46 explicit operator double()
const;
47 explicit operator float()
const;
55 std::string
to_string(
int base = 10)
const;
62template<
typename T,
int S>
struct IntF {
63 static_assert(std::is_unsigned_v<T>);
64 static_assert(S >= 1);
85 explicit operator int64_t()
const;
88 explicit operator double()
const;
89 explicit operator float()
const;
100 std::string
to_string(
int base = 10)
const;
167 constexpr int Count = std::min(S,
int(
sizeof(
decltype(value)) /
sizeof(T)));
168 constexpr int BitsPerT = 8 *
sizeof(
T);
170 for (
int i = 0; i < Count; i++) {
171 this->
v[i] =
T(value >> (BitsPerT * i));
173 for (
int i = Count; i < S; i++) {
180 constexpr int Count = std::min(S,
int(
sizeof(
decltype(value)) /
sizeof(T)));
181 constexpr int BitsPerT = 8 *
sizeof(
T);
183 for (
int i = 0; i < Count; i++) {
184 this->
v[i] =
T(value >> (BitsPerT * i));
186 const T sign_extend_fill = value < 0 ?
T(-1) :
T(0);
187 for (
int i = Count; i < S; i++) {
188 this->
v[i] = sign_extend_fill;
196 this->set_from_str(
str, base);
201 this->set_from_str(
str, base);
206 constexpr int Count = std::min(S,
int(
sizeof(
uint64_t) /
sizeof(T)));
207 constexpr int BitsPerT = 8 *
sizeof(
T);
210 for (
int i = 0; i < Count; i++) {
211 result |=
uint64_t(this->
v[i]) << (BitsPerT * i);
218 double result =
double(this->
v[0]);
219 for (
int i = 1; i < S; i++) {
220 const T a = this->
v[i];
224 result += ldexp(a, 8 *
sizeof(T) * i);
231 return float(
double(*
this));
244 double result =
double(this->
v[0]);
245 for (
int i = 1; i < S; i++) {
246 const T a = this->
v[i];
250 result += ldexp(a, 8 *
sizeof(T) * i);
257 return float(
double(*
this));
278template<
typename T,
typename T2,
int S>
281 constexpr int shift = 8 *
sizeof(
T);
284 const T2 ai =
T2(a[i]);
285 const T2 bi =
T2(
b[i]);
286 const T2 ri = ai + bi + carry;
295template<
typename T,
typename T2,
int S>
300 const T2 ai =
T2(a[i]);
301 const T2 bi =
T2(
b[i]);
302 const T2 ri = ai - bi - carry;
309template<
typename T,
typename T2,
int S>
312 constexpr int shift = 8 *
sizeof(
T);
316 for (
int i = 0; i < S; i++) {
317 const T2 bi =
T2(
b[i]);
319 for (
int j = 0; j < S - i; j++) {
320 const T2 rji =
T2(a[j]) * bi + carry;
321 carry = rji >> shift;
322 r[i + j] +=
T2(
T(rji));
327 for (
int i = 0; i < S; i++) {
328 const T2 ri = r[i] + carry;
334template<
typename T,
int Size, BLI_ENABLE_IF((!std::is_
void_v<
double_u
int_type<T>>))>
342template<
typename T,
int Size, BLI_ENABLE_IF((!std::is_
void_v<
double_u
int_type<T>>))>
350template<
typename T,
int Size>
358template<
typename T,
int Size>
366template<
typename T,
int Size, BLI_ENABLE_IF((!std::is_
void_v<
double_u
int_type<T>>))>
380 return (a.v[Size - 1] & (T(1) << (
sizeof(T) * 8 - 1))) != 0;
397template<
typename T,
int Size, BLI_ENABLE_IF((!std::is_
void_v<
double_u
int_type<T>>))>
406 if (is_negative_a && is_negative_b) {
421 for (
int i = 0; i < Size; i++) {
422 result.
v[i] = ~a.v[i];
457template<
typename T,
int Size>
463template<
typename T,
int Size>
469template<
typename T,
int Size>
475template<
typename T,
int Size>
481template<
typename T,
size_t Size>
484 for (
int i = Size - 1; i >= 0; i--) {
495template<
typename T,
int Size>
500 if (is_negative_a == is_negative_b) {
503 return is_negative_a;
506template<
typename T,
int Size>
511 if (is_negative_a == is_negative_b) {
514 return is_negative_a;
517template<
typename T,
int Size>
522 if (is_negative_a == is_negative_b) {
525 return is_negative_b;
528template<
typename T,
int Size>
533 if (is_negative_a == is_negative_b) {
536 return is_negative_b;
539template<
typename T,
int Size>
545template<
typename T,
int Size>
551template<
typename T,
int Size>
557template<
typename T,
int Size>
typedef double(DMatrix)[4][4]
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
static const char * to_string(const Interpolation &interp)
void operator*=(UIntF< T, Size > &a, const UIntF< T, Size > &b)
UIntF< T, Size > operator*(const UIntF< T, Size > &a, const UIntF< T, Size > &b)
bool is_zero(const UIntF< T, Size > &a)
void operator+=(UIntF< T, Size > &a, const UIntF< T, Size > &b)
bool operator!=(const IntF< T, Size > &a, const IntF< T, Size > &b)
UIntF< T, Size > operator-(const UIntF< T, Size > &a, const UIntF< T, Size > &b)
IntF< uint64_t, 4 > Int256_64
UIntF< uint32_t, 4 > UInt128_32
IntF< uint32_t, 8 > Int256_32
UIntF< T, Size > operator+(const UIntF< T, Size > &a, const UIntF< T, Size > &b)
int compare_reversed_order(const std::array< T, Size > &a, const std::array< T, Size > &b)
IntF< uint32_t, 4 > Int128_32
bool operator==(const IntF< T, Size > &a, const IntF< T, Size > &b)
bool operator>(const IntF< T, Size > &a, const IntF< T, Size > &b)
void generic_unsigned_mul(T *__restrict dst, const T *a, const T *b)
UIntF< uint32_t, 8 > UInt256_32
IntF< uint64_t, 2 > Int128_64
typename DoubleUIntType< T >::type double_uint_type
bool operator>=(const IntF< T, Size > &a, const IntF< T, Size > &b)
void generic_add(T *__restrict dst, const T *a, const T *b)
void generic_sub(T *__restrict dst, const T *a, const T *b)
UIntF< uint64_t, 4 > UInt256_64
UIntF< uint64_t, 2 > UInt128_64
bool operator<(const IntF< T, Size > &a, const IntF< T, Size > &b)
bool operator<=(const IntF< T, Size > &a, const IntF< T, Size > &b)
bool is_negative(const IntF< T, Size > &a)
void operator-=(UIntF< T, Size > &a, const UIntF< T, Size > &b)
unsigned __int64 uint64_t