39
39
// llcommon depend on llmath.
40
40
#include " is_approx_equal_fraction.h"
41
41
42
- // work around for Windows & older gcc non-standard function names.
43
- #if LL_WINDOWS
44
- #include < float.h>
45
- #define llisnan (val ) _isnan(val)
46
- #define llfinite (val ) _finite(val)
47
- #elif (LL_LINUX && __GNUC__ <= 2)
48
- #define llisnan (val ) isnan(val)
49
- #define llfinite (val ) isfinite(val)
50
- #else
51
- #define llisnan (val ) std::isnan(val)
52
- #define llfinite (val ) std::isfinite(val)
53
- #endif
42
+ #define llisnan (val ) std::isnan(val)
43
+ #define llfinite (val ) std::isfinite(val)
54
44
55
45
// Single Precision Floating Point Routines
56
46
// (There used to be more defined here, but they appeared to be redundant and
@@ -89,7 +79,7 @@ constexpr F32 GIMBAL_THRESHOLD = 0.000436f; // sets the gimballock threshold 0
89
79
constexpr F32 FP_MAG_THRESHOLD = 0 .0000001f ;
90
80
91
81
// TODO: Replace with logic like is_approx_equal
92
- inline bool is_approx_zero ( F32 f ) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
82
+ constexpr bool is_approx_zero (F32 f) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
93
83
94
84
// These functions work by interpreting sign+exp+mantissa as an unsigned
95
85
// integer.
@@ -148,33 +138,17 @@ inline F64 llabs(const F64 a)
148
138
return F64 (std::fabs (a));
149
139
}
150
140
151
- inline S32 lltrunc ( F32 f )
141
+ constexpr S32 lltrunc (F32 f)
152
142
{
153
- #if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32)
154
- // Avoids changing the floating point control word.
155
- // Add or subtract 0.5 - epsilon and then round
156
- const static U32 zpfp[] = { 0xBEFFFFFF , 0x3EFFFFFF };
157
- S32 result;
158
- __asm {
159
- fld f
160
- mov eax, f
161
- shr eax, 29
162
- and eax, 4
163
- fadd dword ptr [zpfp + eax]
164
- fistp result
165
- }
166
- return result;
167
- #else
168
- return (S32)f;
169
- #endif
143
+ return narrow (f);
170
144
}
171
145
172
- inline S32 lltrunc ( F64 f )
146
+ constexpr S32 lltrunc (F64 f)
173
147
{
174
- return (S32)f ;
148
+ return narrow (f) ;
175
149
}
176
150
177
- inline S32 llfloor ( F32 f )
151
+ inline S32 llfloor (F32 f)
178
152
{
179
153
#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32)
180
154
// Avoids changing the floating point control word.
@@ -284,7 +258,7 @@ constexpr F32 FAST_MAG_BETA = 0.397824734759f;
284
258
// constexpr F32 FAST_MAG_ALPHA = 0.948059448969f;
285
259
// constexpr F32 FAST_MAG_BETA = 0.392699081699f;
286
260
287
- inline F32 fastMagnitude (F32 a, F32 b)
261
+ constexpr F32 fastMagnitude (F32 a, F32 b)
288
262
{
289
263
a = (a > 0 ) ? a : -a;
290
264
b = (b > 0 ) ? b : -b;
@@ -342,7 +316,7 @@ inline F32 llfastpow(const F32 x, const F32 y)
342
316
}
343
317
344
318
345
- inline F32 snap_to_sig_figs (F32 foo, S32 sig_figs)
319
+ constexpr F32 snap_to_sig_figs (F32 foo, S32 sig_figs)
346
320
{
347
321
// compute the power of ten
348
322
F32 bar = 1 .f ;
@@ -358,30 +332,27 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
358
332
return new_foo;
359
333
}
360
334
361
- inline F32 lerp (F32 a, F32 b, F32 u)
362
- {
363
- return a + ((b - a) * u);
364
- }
335
+ using std::lerp;
365
336
366
- inline F32 lerp2d (F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
337
+ constexpr F32 lerp2d (F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
367
338
{
368
339
F32 a = x00 + (x01-x00)*u;
369
340
F32 b = x10 + (x11-x10)*u;
370
341
F32 r = a + (b-a)*v;
371
342
return r;
372
343
}
373
344
374
- inline F32 ramp (F32 x, F32 a, F32 b)
345
+ constexpr F32 ramp (F32 x, F32 a, F32 b)
375
346
{
376
347
return (a == b) ? 0 .0f : ((a - x) / (a - b));
377
348
}
378
349
379
- inline F32 rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
350
+ constexpr F32 rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
380
351
{
381
352
return lerp (y1, y2, ramp (x, x1, x2));
382
353
}
383
354
384
- inline F32 clamp_rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
355
+ constexpr F32 clamp_rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
385
356
{
386
357
if (y1 < y2)
387
358
{
@@ -394,7 +365,7 @@ inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
394
365
}
395
366
396
367
397
- inline F32 cubic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
368
+ constexpr F32 cubic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
398
369
{
399
370
if (x <= x0)
400
371
return s0;
@@ -407,14 +378,14 @@ inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
407
378
return s0 + (s1 - s0) * (f * f) * (3 .0f - 2 .0f * f);
408
379
}
409
380
410
- inline F32 cubic_step ( F32 x )
381
+ constexpr F32 cubic_step ( F32 x )
411
382
{
412
383
x = llclampf (x);
413
384
414
385
return (x * x) * (3 .0f - 2 .0f * x);
415
386
}
416
387
417
- inline F32 quadratic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
388
+ constexpr F32 quadratic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
418
389
{
419
390
if (x <= x0)
420
391
return s0;
@@ -428,7 +399,7 @@ inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
428
399
return (s0 * (1 .f - f_squared)) + ((s1 - s0) * f_squared);
429
400
}
430
401
431
- inline F32 llsimple_angle (F32 angle)
402
+ constexpr F32 llsimple_angle (F32 angle)
432
403
{
433
404
while (angle <= -F_PI)
434
405
angle += F_TWO_PI;
@@ -438,7 +409,7 @@ inline F32 llsimple_angle(F32 angle)
438
409
}
439
410
440
411
// SDK - Renamed this to get_lower_power_two, since this is what this actually does.
441
- inline U32 get_lower_power_two (U32 val, U32 max_power_two)
412
+ constexpr U32 get_lower_power_two (U32 val, U32 max_power_two)
442
413
{
443
414
if (!max_power_two)
444
415
{
@@ -460,7 +431,7 @@ inline U32 get_lower_power_two(U32 val, U32 max_power_two)
460
431
// number of digits, then add one. We subtract 1 initially to handle
461
432
// the case where the number passed in is actually a power of two.
462
433
// WARNING: this only works with 32 bit ints.
463
- inline U32 get_next_power_two (U32 val, U32 max_power_two)
434
+ constexpr U32 get_next_power_two (U32 val, U32 max_power_two)
464
435
{
465
436
if (!max_power_two)
466
437
{
@@ -486,7 +457,7 @@ inline U32 get_next_power_two(U32 val, U32 max_power_two)
486
457
// get the gaussian value given the linear distance from axis x and guassian value o
487
458
inline F32 llgaussian (F32 x, F32 o)
488
459
{
489
- return 1 .f /(F_SQRT_TWO_PI*o)*powf (F_E, -(x*x)/(2 *o*o));
460
+ return 1 .f /(F_SQRT_TWO_PI*o)*powf (F_E, -(x*x)/(2 . f *o*o));
490
461
}
491
462
492
463
// helper function for removing outliers
@@ -539,7 +510,8 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
539
510
// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
540
511
// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
541
512
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses
542
- inline float linearTosRGB (const float val) {
513
+ inline float linearTosRGB (const float val)
514
+ {
543
515
if (val < 0 .0031308f ) {
544
516
return val * 12 .92f ;
545
517
}
@@ -554,7 +526,8 @@ inline float linearTosRGB(const float val) {
554
526
// Note: Stored color values should generally be gamma corrected sRGB.
555
527
// If you're serializing the return value of this function, you're probably doing it wrong.
556
528
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
557
- inline float sRGBtoLinear (const float val) {
529
+ inline float sRGBtoLinear (const float val)
530
+ {
558
531
if (val < 0 .04045f ) {
559
532
return val / 12 .92f ;
560
533
}
0 commit comments