libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Macros | Functions
math_core.h File Reference
#include <math.h>
#include "assert.h"
#include "core.h"
Include dependency graph for math_core.h:

Go to the source code of this file.

Macros

#define DEFN_CLAMP(name, type, assert_chk)
 

Functions

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)
 

Macro Definition Documentation

◆ 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.

Function Documentation

◆ clamp()

static double clamp ( double  x,
double  min_val,
double  max_val 
)
static

Clamps a number between two double precision floating point numbers.

Parameters
xThe number to clamp.
min_valMinimum value. If x < min_val, min_val is returned.
min_valMaximum 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.