@@ -89,7 +89,7 @@ constexpr F32 GIMBAL_THRESHOLD = 0.000436f; // sets the gimballock threshold 0
89
89
constexpr F32 FP_MAG_THRESHOLD = 0 .0000001f ;
90
90
91
91
// 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); }
92
+ constexpr bool is_approx_zero (F32 f) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
93
93
94
94
// These functions work by interpreting sign+exp+mantissa as an unsigned
95
95
// integer.
@@ -148,33 +148,17 @@ inline F64 llabs(const F64 a)
148
148
return F64 (std::fabs (a));
149
149
}
150
150
151
- inline S32 lltrunc ( F32 f )
151
+ constexpr S32 lltrunc (F32 f)
152
152
{
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
153
+ return narrow (f);
170
154
}
171
155
172
- inline S32 lltrunc ( F64 f )
156
+ constexpr S32 lltrunc (F64 f)
173
157
{
174
- return (S32)f ;
158
+ return narrow (f) ;
175
159
}
176
160
177
- inline S32 llfloor ( F32 f )
161
+ inline S32 llfloor (F32 f)
178
162
{
179
163
#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32)
180
164
// Avoids changing the floating point control word.
@@ -284,7 +268,7 @@ constexpr F32 FAST_MAG_BETA = 0.397824734759f;
284
268
// constexpr F32 FAST_MAG_ALPHA = 0.948059448969f;
285
269
// constexpr F32 FAST_MAG_BETA = 0.392699081699f;
286
270
287
- inline F32 fastMagnitude (F32 a, F32 b)
271
+ constexpr F32 fastMagnitude (F32 a, F32 b)
288
272
{
289
273
a = (a > 0 ) ? a : -a;
290
274
b = (b > 0 ) ? b : -b;
@@ -342,7 +326,7 @@ inline F32 llfastpow(const F32 x, const F32 y)
342
326
}
343
327
344
328
345
- inline F32 snap_to_sig_figs (F32 foo, S32 sig_figs)
329
+ constexpr F32 snap_to_sig_figs (F32 foo, S32 sig_figs)
346
330
{
347
331
// compute the power of ten
348
332
F32 bar = 1 .f ;
@@ -360,25 +344,25 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
360
344
361
345
using std::lerp;
362
346
363
- inline F32 lerp2d (F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
347
+ constexpr F32 lerp2d (F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
364
348
{
365
349
F32 a = x00 + (x01-x00)*u;
366
350
F32 b = x10 + (x11-x10)*u;
367
351
F32 r = a + (b-a)*v;
368
352
return r;
369
353
}
370
354
371
- inline F32 ramp (F32 x, F32 a, F32 b)
355
+ constexpr F32 ramp (F32 x, F32 a, F32 b)
372
356
{
373
357
return (a == b) ? 0 .0f : ((a - x) / (a - b));
374
358
}
375
359
376
- inline F32 rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
360
+ constexpr F32 rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
377
361
{
378
362
return lerp (y1, y2, ramp (x, x1, x2));
379
363
}
380
364
381
- inline F32 clamp_rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
365
+ constexpr F32 clamp_rescale (F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
382
366
{
383
367
if (y1 < y2)
384
368
{
@@ -391,7 +375,7 @@ inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
391
375
}
392
376
393
377
394
- inline F32 cubic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
378
+ constexpr F32 cubic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
395
379
{
396
380
if (x <= x0)
397
381
return s0;
@@ -404,14 +388,14 @@ inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
404
388
return s0 + (s1 - s0) * (f * f) * (3 .0f - 2 .0f * f);
405
389
}
406
390
407
- inline F32 cubic_step ( F32 x )
391
+ constexpr F32 cubic_step ( F32 x )
408
392
{
409
393
x = llclampf (x);
410
394
411
395
return (x * x) * (3 .0f - 2 .0f * x);
412
396
}
413
397
414
- inline F32 quadratic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
398
+ constexpr F32 quadratic_step ( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
415
399
{
416
400
if (x <= x0)
417
401
return s0;
@@ -425,7 +409,7 @@ inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
425
409
return (s0 * (1 .f - f_squared)) + ((s1 - s0) * f_squared);
426
410
}
427
411
428
- inline F32 llsimple_angle (F32 angle)
412
+ constexpr F32 llsimple_angle (F32 angle)
429
413
{
430
414
while (angle <= -F_PI)
431
415
angle += F_TWO_PI;
@@ -435,7 +419,7 @@ inline F32 llsimple_angle(F32 angle)
435
419
}
436
420
437
421
// SDK - Renamed this to get_lower_power_two, since this is what this actually does.
438
- inline U32 get_lower_power_two (U32 val, U32 max_power_two)
422
+ constexpr U32 get_lower_power_two (U32 val, U32 max_power_two)
439
423
{
440
424
if (!max_power_two)
441
425
{
@@ -457,7 +441,7 @@ inline U32 get_lower_power_two(U32 val, U32 max_power_two)
457
441
// number of digits, then add one. We subtract 1 initially to handle
458
442
// the case where the number passed in is actually a power of two.
459
443
// WARNING: this only works with 32 bit ints.
460
- inline U32 get_next_power_two (U32 val, U32 max_power_two)
444
+ constexpr U32 get_next_power_two (U32 val, U32 max_power_two)
461
445
{
462
446
if (!max_power_two)
463
447
{
@@ -536,7 +520,8 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
536
520
// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
537
521
// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
538
522
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses
539
- inline float linearTosRGB (const float val) {
523
+ inline float linearTosRGB (const float val)
524
+ {
540
525
if (val < 0 .0031308f ) {
541
526
return val * 12 .92f ;
542
527
}
@@ -551,7 +536,8 @@ inline float linearTosRGB(const float val) {
551
536
// Note: Stored color values should generally be gamma corrected sRGB.
552
537
// If you're serializing the return value of this function, you're probably doing it wrong.
553
538
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
554
- inline float sRGBtoLinear (const float val) {
539
+ inline float sRGBtoLinear (const float val)
540
+ {
555
541
if (val < 0 .04045f ) {
556
542
return val / 12 .92f ;
557
543
}
0 commit comments