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
math_core.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may only use this file in accordance with the terms of version
7 * 1.0 of the CDDL.
8 *
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.illumos.org/license/CDDL.
12 *
13 * CDDL HEADER END
14 */
15/*
16 * Copyright 2023 Saso Kiselkov. All rights reserved.
17 */
20#ifndef _ACF_UTILS_MATH_CORE_H_
21#define _ACF_UTILS_MATH_CORE_H_
22
23#include <math.h>
24
25#include "assert.h"
26#include "core.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
35#define DEFN_CLAMP(name, type, assert_chk) \
36static inline type \
37name(type x, type min_val, type max_val) \
38{ \
39 if (COND_LIKELY(min_val < max_val)) { \
40 if (x < min_val) \
41 return (min_val); \
42 if (x > max_val) \
43 return (max_val); \
44 } else { \
45 if (x > min_val) \
46 return (min_val); \
47 if (x < max_val) \
48 return (max_val); \
49 } \
50 return (x); \
51}
52
69
70#undef DEFN_CLAMP
71
72#ifdef __cplusplus
73}
74#endif
75
76#endif /* _ACF_UTILS_GEOM_H_ */
#define ASSERT3S(x, op, y)
Definition assert.h:209
#define ASSERT3F(x, op, y)
Definition assert.h:211
static long clampl(long x, long min_val, long max_val)
Definition math_core.h:64
#define DEFN_CLAMP(name, type, assert_chk)
Definition math_core.h:35
static double clamp(double x, double min_val, double max_val)
Definition math_core.h:60
static int clampi(int x, int min_val, int max_val)
Definition math_core.h:68