#include <math.h>
#include "assert.h"
#include "core.h"
Go to the source code of this file.
|
static double | clamp (double x, double min_val, double max_val) |
|
static long | clampl (long x, long min_val, long max_val) |
|
static int | clampi (int x, int min_val, int max_val) |
|
◆ DEFN_CLAMP
#define DEFN_CLAMP |
( |
|
name, |
|
|
|
type, |
|
|
|
assert_chk |
|
) |
| |
Value:static inline type \
name(type x, type min_val, type max_val) \
{ \
if (COND_LIKELY(min_val < max_val)) { \
if (x < min_val) \
return (min_val); \
if (x > max_val) \
return (max_val); \
} else { \
if (x > min_val) \
return (min_val); \
if (x < max_val) \
return (max_val); \
} \
return (x); \
}
- Note
- Internal. Do not use.
Definition at line 35 of file math_core.h.
◆ clamp()
static double clamp |
( |
double |
x, |
|
|
double |
min_val, |
|
|
double |
max_val |
|
) |
| |
|
static |
Clamps a number between two double precision floating point numbers.
- Parameters
-
x | The number to clamp. |
min_val | Minimum value. If x < min_val , min_val is returned. |
min_val | Maximum value. If x > max_val , max_val is returned. |
- Returns
- Input
x
clamped so to fit between min_val
and max_val
.
Definition at line 60 of file math_core.h.
◆ clampi()
static int clampi |
( |
int |
x, |
|
|
int |
min_val, |
|
|
int |
max_val |
|
) |
| |
|
static |
Same as clamp(), but takes iint
arguments and returns an int
.
Definition at line 68 of file math_core.h.
◆ clampl()
static long clampl |
( |
long |
x, |
|
|
long |
min_val, |
|
|
long |
max_val |
|
) |
| |
|
static |
Same as clamp(), but takes long int
arguments and returns a long int
.
Definition at line 64 of file math_core.h.