PatchworkOS
Loading...
Searching...
No Matches
Common math macros

Common math macros. More...

Macros

#define MAX(x, y)   (((x) > (y)) ? (x) : (y))
 
#define MIN(x, y)   (((x) < (y)) ? (x) : (y))
 
#define CLAMP(x, low, high)   MIN((high), MAX((low), (x)))
 
#define ROUND_UP(number, multiple)    ((((uint64_t)(number) + (uint64_t)(multiple) - 1) / (uint64_t)(multiple)) * (uint64_t)(multiple))
 
#define ROUND_DOWN(number, multiple)   (((uint64_t)(number) / (uint64_t)(multiple)) * (uint64_t)(multiple))
 
#define LERP_INT(start, end, t, minT, maxT)   (((start) * ((maxT) - (t))) + ((end) * ((t) - (minT)))) / ((maxT) - (minT))
 

Detailed Description

Common math macros.

The sys/math.h header provides common math macros for operations such as clamping, rounding, and linear interpolation.

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   x,
  low,
  high 
)    MIN((high), MAX((low), (x)))

Definition at line 17 of file math.h.

◆ LERP_INT

#define LERP_INT (   start,
  end,
  t,
  minT,
  maxT 
)    (((start) * ((maxT) - (t))) + ((end) * ((t) - (minT)))) / ((maxT) - (minT))

Definition at line 23 of file math.h.

◆ MAX

#define MAX (   x,
  y 
)    (((x) > (y)) ? (x) : (y))

Definition at line 15 of file math.h.

◆ MIN

#define MIN (   x,
  y 
)    (((x) < (y)) ? (x) : (y))

Definition at line 16 of file math.h.

◆ ROUND_DOWN

#define ROUND_DOWN (   number,
  multiple 
)    (((uint64_t)(number) / (uint64_t)(multiple)) * (uint64_t)(multiple))

Definition at line 21 of file math.h.

◆ ROUND_UP

#define ROUND_UP (   number,
  multiple 
)     ((((uint64_t)(number) + (uint64_t)(multiple) - 1) / (uint64_t)(multiple)) * (uint64_t)(multiple))

Definition at line 19 of file math.h.