PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
Math Helpers

Helper Macros for math operations. More...

Collaboration diagram for Math Helpers:

Detailed Description

Helper Macros for math operations.

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

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))
 
#define IS_POW2(x)   (((x) & ((x) - 1)) == 0)
 

Functions

uint64_t next_pow2 (uint64_t n)
 

Macro Definition Documentation

◆ MAX

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

Definition at line 17 of file math.h.

◆ MIN

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

Definition at line 18 of file math.h.

◆ CLAMP

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

Definition at line 19 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 21 of file math.h.

◆ ROUND_DOWN

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

Definition at line 23 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 25 of file math.h.

◆ IS_POW2

#define IS_POW2 (   x)    (((x) & ((x) - 1)) == 0)

Definition at line 27 of file math.h.

Function Documentation

◆ next_pow2()

uint64_t next_pow2 ( uint64_t  n)

Definition at line 3 of file new_pow2.c.

Here is the caller graph for this function: