Blender V5.0
BLI_math_constants.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11/* On Windows we have to include math.h before defining our own constants, to
12 * avoid warnings about redefinition. This can likely be simplified later when
13 * code is fully converted to C++, not defining our own constants at all. */
14#if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
15# define _USE_MATH_DEFINES
16#endif
17
18#include <math.h> /* IWYU pragma: export */
19
20#ifndef M_PI
21# define M_PI 3.14159265358979323846 /* `pi` */
22#endif
23#ifndef M_TAU
24# define M_TAU 6.28318530717958647692 /* `tau = 2*pi` */
25#endif
26#ifndef M_PI_2
27# define M_PI_2 1.57079632679489661923 /* `pi/2` */
28#endif
29#ifndef M_PI_4
30# define M_PI_4 0.78539816339744830962 /* `pi/4` */
31#endif
32#ifndef M_SQRT2
33# define M_SQRT2 1.41421356237309504880 /* `sqrt(2)` */
34#endif
35#ifndef M_SQRT1_2
36# define M_SQRT1_2 0.70710678118654752440 /* `1/sqrt(2)` */
37#endif
38#ifndef M_SQRT3
39# define M_SQRT3 1.73205080756887729352 /* `sqrt(3)` */
40#endif
41#ifndef M_SQRT1_3
42# define M_SQRT1_3 0.57735026918962576450 /* `1/sqrt(3)` */
43#endif
44#ifndef M_1_PI
45# define M_1_PI 0.318309886183790671538 /* `1/pi` */
46#endif
47#ifndef M_E
48# define M_E 2.7182818284590452354 /* `e` */
49#endif
50#ifndef M_LOG2E
51# define M_LOG2E 1.4426950408889634074 /* `log_2 e` */
52#endif
53#ifndef M_LOG10E
54# define M_LOG10E 0.43429448190325182765 /* `log_10 e` */
55#endif
56#ifndef M_LN2
57# define M_LN2 0.69314718055994530942 /* `log_e 2` */
58#endif
59#ifndef M_LN10
60# define M_LN10 2.30258509299404568402 /* `log_e 10` */
61#endif
62
63#if defined(_MSC_VER) && !defined(_MATH_DEFINES_DEFINED)
64# define _MATH_DEFINES_DEFINED
65#endif
66
67/* -------------------------------------------------------------------- */
70
71#define RAD2DEG(_rad) ((_rad) * (180.0 / M_PI))
72#define DEG2RAD(_deg) ((_deg) * (M_PI / 180.0))
73
74#define RAD2DEGF(_rad) ((_rad) * (float)(180.0 / M_PI))
75#define DEG2RADF(_deg) ((_deg) * (float)(M_PI / 180.0))
76