23#define PI (3.1415926535897932384626433832795028841971693993751)
28#define N_PI (Math::scalar(PI))
32#define N_PI_DOUBLE (Math::scalar(6.283185307179586476925286766559))
36#define N_PI_HALF (Math::scalar(1.5707963267948966192313216916398f))
41#define TINY (0.0000001f)
50#define PI (3.1415926535897932384626433832795028841971693993751)
54#define N_PI (Math::scalar(3.1415926535897932384626433832795028841971693993751))
97 struct {
int x,
y,
z; };
115 struct {
unsigned int x,
y; };
124 struct {
unsigned int x,
y,
z; };
133 struct {
unsigned int x,
y,
z,
w; };
175 return min + unit * diff;
271 static const scalar rev =
scalar(6.283185307179586476925286766559);
272 return n_fmod(a,rev);
274 static const scalar REVOLUTION =
scalar(6.283185307179586476925286766559);
277 temp = temp - floorf(temp/REVOLUTION) * REVOLUTION;
279 temp = a<0 ? -temp:temp;
331 return fchop(floorf(f + 0.5f));
351 return ((f > (-tol)) && (f < tol));
357template<
typename TYPE>
361 return (a > b) ? a : b;
367template<
typename TYPE0,
typename ...TYPEN>
369max(TYPE0 first, TYPE0 second, TYPEN... rest)
371 return first > second ?
max(first, std::forward<TYPEN>(rest)...) :
max(second, std::forward<TYPEN>(rest)...);
379__forceinline
unsigned int
380max(
unsigned int a,
unsigned int b)
382 return a ^ ((a ^ b) & -(a < b));
388template<
typename TYPE>
392 return (a < b) ? a : b;
400__forceinline
unsigned int
401min(
unsigned int a,
unsigned int b)
403 return b ^ ((a ^ b) & -(a < b));
411__forceinline uint16_t
412min(uint16_t a, uint16_t b)
414 return b ^ ((a ^ b) & -(a < b));
420template<
typename TYPE0,
typename ...TYPEN>
422min(TYPE0 first, TYPE0 second, TYPEN... rest)
424 return first < second ? min(first, std::forward<TYPEN>(rest)...) :
min(second, std::forward<TYPEN>(rest)...);
434 return (a < 0.0f) ? -a : a;
443 return (a < 0.0) ? -a : a;
452 return (a < 0) ? -a : a;
461 return (a < 0.0f) ? -1.0f : 1.0f;
467__forceinline
constexpr scalar
476__forceinline
constexpr scalar
487clamp(
float val,
float minVal,
float maxVal)
489 if (val < minVal)
return minVal;
490 else if (val > maxVal)
return maxVal;
499clamp(int64_t val, int64_t minVal, int64_t maxVal)
501 if (val < minVal)
return minVal;
502 else if (val > maxVal)
return maxVal;
511clamp(int32_t val, int32_t minVal, int32_t maxVal)
513 if (val < minVal)
return minVal;
514 else if (val > maxVal)
return maxVal;
555 return ((f0 - f1) < tol);
565 return ((f0 - f1) > tol);
575 if (val < 0.0f)
return 0.0f;
576 else if (val > 1.0f)
return 1.0f;
587 if (val < 0.0)
return 0.0;
588 else if (val > 1.0)
return 1.0;
599 return x + l * (y - x);
611 scalar dist = normTo - normFrom;
616 else if (dist >
deg2rad(180.0f))
631 union {
scalar s;
unsigned int u; } pun;
633 return ((pun.u&0x7f800000)==0);
635 return (((*(
unsigned int*)&s)&0x7f800000)==0);
663 return abs(a - b) <= epsilon;
682 x =
saturate((x - edge0) / (edge1 - edge0));
694 int range =
max -
min + 1;
695 int unit =
::rand() % range;
708 bool res = _BitScanReverse(&ret, val);
713 ret = __builtin_clz(val);
721__forceinline
unsigned int
722align(
unsigned int alignant,
unsigned int alignment)
724 return (alignant + alignment - 1) & ~(alignment - 1);
730__forceinline uintptr_t
733 return (alignant + alignment - 1) & ~(alignment - 1);
739__forceinline
unsigned int
742 return (alignant / alignment * alignment);
748__forceinline uintptr_t
751 return (alignant / alignment * alignment);
758__forceinline
unsigned int
761 return (dividend % divider != 0) ? (dividend / divider + 1) : (dividend / divider);
768__forceinline
unsigned int
793 uint64_t t = state.x[0];
794 uint64_t
const s = state.x[1];
807__forceinline uint32_t
810 return (uint32_t) (((uintptr_t)(
void *)ptr) % 4294967291u);
821 return (
float)value / 65535.0f;
831 return Math::max((
float)value / 32767.0f, -1.0f);
841 return (
float)value / 255.0f;
851 return Math::max((
float)value / 127.0f, -1.0f);
861operator"" _rad(
long double deg)
870operator"" _rad(
unsigned long long deg)
880operator"" _deg(
long double rad)
889operator"" _deg(
unsigned long long deg)
Different curves.
Definition angularpfeedbackloop.h:17
__forceinline uintptr_t alignptr(uintptr_t alignant, uintptr_t alignment)
Definition scalar.h:731
__forceinline float undenormalize(scalar s)
Returns 0 if scalar is denormal.
Definition scalar.h:644
__forceinline constexpr scalar rad2deg(scalar r)
Definition scalar.h:477
__forceinline int mostsignificant(unsigned int val)
Returns the position of the most significant bit of the number.
Definition scalar.h:704
__forceinline bool fequal(scalar f0, scalar f1, scalar tol)
A fuzzy floating point equality check.
Definition scalar.h:348
__forceinline scalar cot(scalar x)
Definition scalar.h:670
__forceinline scalar sqrt(scalar x)
Definition scalar.h:236
__forceinline uint64 randxor(randxorstate &state)
Definition scalar.h:791
__forceinline scalar log(scalar x)
get logarithm of x
Definition scalar.h:310
__forceinline unsigned int align_down(unsigned int alignant, unsigned int alignment)
Definition scalar.h:740
__forceinline constexpr scalar deg2rad(scalar d)
Definition scalar.h:468
__forceinline scalar asin(scalar x)
Definition scalar.h:209
__forceinline scalar saturate(scalar val)
Saturate a value (clamps between 0.0f and 1.0f)
Definition scalar.h:573
__forceinline uint32_t pointerhash(void *ptr)
cheap pointer hash using modulo with a mersenne prime
Definition scalar.h:808
__forceinline scalar log2(scalar f)
log2() function.
Definition scalar.h:291
__forceinline int fchop(scalar f)
Chop float to int.
Definition scalar.h:246
float normtofloat(uint16_t value)
convert normalized uint16_t to float
Definition scalar.h:819
__forceinline int frnd(scalar f)
Round float to integer.
Definition scalar.h:329
__forceinline float round(float val)
Floating point rounding.
Definition scalar.h:543
__forceinline float ceil(float val)
Floating point ceiling.
Definition scalar.h:523
__forceinline float lerp(float x, float y, float l)
Linearly interpolate between 2 values: ret = x + l * (y - x)
Definition scalar.h:597
__forceinline scalar modangle(scalar a)
Normalize an angular value into the range rad(0) to rad(360).
Definition scalar.h:268
__forceinline int irand(int min, int max)
Return a pseudo integer random number between min and max.
Definition scalar.h:692
__forceinline scalar pow(scalar x, scalar y)
Definition scalar.h:338
__forceinline float clamp(float val, float minVal, float maxVal)
Float clamping.
Definition scalar.h:487
__forceinline unsigned int align(unsigned int alignant, unsigned int alignment)
Definition scalar.h:722
__forceinline scalar rand()
Return a pseudo random number between 0 and 1.
Definition scalar.h:161
__forceinline TYPE min(TYPE a, TYPE b)
Definition scalar.h:390
__forceinline bool isdenormal(scalar s)
Returns true if the input scalar is denormalized (#DEN)
Definition scalar.h:628
double float64
Definition scalar.h:47
__forceinline scalar smoothstep(scalar edge0, scalar edge1, scalar x)
Definition scalar.h:679
__forceinline scalar angulardistance(scalar from, scalar to)
Get angular distance.
Definition scalar.h:607
float scalar
Definition scalar.h:45
__forceinline uintptr_t align_downptr(uintptr_t alignant, uintptr_t alignment)
Definition scalar.h:749
__forceinline scalar exp(scalar x)
Definition scalar.h:319
__forceinline scalar exp2(scalar x)
Definition scalar.h:300
__forceinline TYPE max(TYPE a, TYPE b)
Definition scalar.h:359
__forceinline scalar sgn(scalar a)
Definition scalar.h:459
__forceinline scalar abs(scalar a)
Definition scalar.h:432
__forceinline scalar cos(scalar x)
Definition scalar.h:191
__forceinline unsigned int divandroundup(unsigned int dividend, unsigned int divider)
Integer division with rounding.
Definition scalar.h:759
__forceinline scalar acos(scalar x)
Definition scalar.h:218
__forceinline bool nearequal(const point &v0, const point &v1, float epsilon)
Definition point.h:485
__forceinline scalar sin(scalar x)
Definition scalar.h:182
__forceinline bool fless(scalar f0, scalar f1, scalar tol)
A fuzzy floating point less-then check.
Definition scalar.h:553
__forceinline bool fgreater(scalar f0, scalar f1, scalar tol)
A fuzzy floating point greater-then check.
Definition scalar.h:563
__forceinline unsigned int roundtopow2(unsigned int val)
Rounds up to next power of 2.
Definition scalar.h:769
__forceinline scalar atan(scalar x)
Definition scalar.h:227
__forceinline float floor(float val)
Floating point flooring.
Definition scalar.h:533
__forceinline scalar tan(scalar x)
Definition scalar.h:200
float float32
Definition scalar.h:46
__forceinline scalar fmod(scalar x, scalar y)
Definition scalar.h:256
#define N_PI
Definition scalar.h:28
byte y
Definition scalar.h:151
byte w
Definition scalar.h:151
byte z
Definition scalar.h:151
unsigned int v
Definition scalar.h:152
byte x
Definition scalar.h:151
ubyte x
Definition scalar.h:142
unsigned int v
Definition scalar.h:143
ubyte z
Definition scalar.h:142
ubyte w
Definition scalar.h:142
ubyte y
Definition scalar.h:142
scalar x
Definition scalar.h:61
scalar v[2]
Definition scalar.h:62
scalar y
Definition scalar.h:61
scalar x
Definition scalar.h:70
scalar y
Definition scalar.h:70
scalar v[3]
Definition scalar.h:71
scalar z
Definition scalar.h:70
scalar x
Definition scalar.h:79
scalar v[4]
Definition scalar.h:80
scalar y
Definition scalar.h:79
scalar w
Definition scalar.h:79
scalar z
Definition scalar.h:79
int v[2]
Definition scalar.h:89
int y
Definition scalar.h:88
int x
Definition scalar.h:88
int x
Definition scalar.h:97
int z
Definition scalar.h:97
int v[3]
Definition scalar.h:98
int y
Definition scalar.h:97
int z
Definition scalar.h:106
int w
Definition scalar.h:106
int x
Definition scalar.h:106
int y
Definition scalar.h:106
int v[4]
Definition scalar.h:107
fast random generator based on xorshift+
Definition scalar.h:786
uint64 x[2]
Definition scalar.h:787
unsigned int x
Definition scalar.h:115
unsigned int v[2]
Definition scalar.h:116
unsigned int y
Definition scalar.h:115
unsigned int z
Definition scalar.h:124
unsigned int y
Definition scalar.h:124
unsigned int v[3]
Definition scalar.h:125
unsigned int x
Definition scalar.h:124
unsigned int w
Definition scalar.h:133
unsigned int z
Definition scalar.h:133
unsigned int x
Definition scalar.h:133
unsigned int y
Definition scalar.h:133
unsigned int v[4]
Definition scalar.h:134
unsigned char ubyte
Definition types.h:34
uint64_t uint64
Definition types.h:36