XenevaOS
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
30#ifndef __MATH_H__
31#define __MATH_H__
32
33#include <_xeneva.h>
34#include <stdint.h>
35#include <string.h>
36
37#ifdef __cplusplus
39#endif
40
41#define M_E 2.7182818284590452354 // e
42#define M_LOG2E 1.4426950408889634074 // log_2 e
43#define M_LOG10E 0.43429448190325182765 // log_10 e
44#define M_LN2 0.69314718055994530942 // log_e 2
45#define M_LN10 2.30258509299404568402 // log_e 10
46#define M_PI 3.14159265358979323846 // pi
47#define M_PI_2 1.57079632679489661923 // pi/2
48#define M_PI_4 0.78539816339744830962 // pi/4
49#define M_1_PI 0.31830988618379067154 // 1/pi
50#define M_2_PI 0.63661977236758134308 // 2/pi
51#define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi)
52#define M_SQRT2 1.41421356237309504880 // sqrt(2)
53#define M_SQRT1_2 0.70710678118654752440 // 1/sqrt(2)
54
55 typedef union {
56 float f;
59
60 typedef union {
61 double d;
64
65 //#define asuint(f) ((union{float _f; uint32_t _i;}){f})._i
66 static INLINE uint32_t asuint(float f) {
68 memset(&u, 0, sizeof(float_bits_t));
69 u.f = f;
70 return u.i;
71 }
72
73 static INLINE float asfloat(uint32_t u) {
74 float_bits_t fb;
75 memset(&fb, 0, sizeof(float_bits_t));
76 fb.i = u;
77 return fb.f;
78 }
79
80 static INLINE uint64_t asuint64(double d) {
82 memset(&db, 0, sizeof(double_bits_t));
83 db.d = d;
84 return db.i;
85 }
86
87 static INLINE double asdouble(uint64_t u) {
89 memset(&db, 0, sizeof(double_bits_t));
90 db.i = u;
91 return db.d;
92 }
93
94#define EXTRACT_WORDS(hi, lo, d) \
95 do { \
96 uint64_t __u = asuint64(d); \
97 (hi) = __u >> 32; \
98 (lo) = (uint32_t)__u; \
99 } while (0)
100
101#define GET_HIGH_WORD(hi, d) \
102 do { \
103 (hi) = asuint64(d) >> 32; \
104 } while (0)
105
106#define GET_LOW_WORD(lo, d) \
107 do { \
108 (lo) = (uint32_t)asuint64(d); \
109 } while (0)
110
111#define INSERT_WORDS(d, hi, lo) \
112 do { \
113 (d) = asdouble(((uint64_t)(hi) << 32) | (uint32_t)(lo)); \
114 } while (0)
115
116#define SET_HIGH_WORD(d, hi) INSERT_WORDS(d, hi, (uint32_t)asuint64(d))
117
118#define SET_LOW_WORD(d, lo) INSERT_WORDS(d, asuint64(d) >> 32, lo)
119
120#define GET_FLOAT_WORD(w, d) \
121 do { \
122 (w) = asuint(d); \
123 } while (0)
124
125#define SET_FLOAT_WORD(d, w) \
126 do { \
127 (d) = asfloat(w); \
128 } while (0)
129
131
132 static INLINE void fp_force_evalf(float x) {
133 volatile float y;
134 y = x;
135 }
136
137 static INLINE void fp_force_eval(double x) {
138 volatile double y;
139 y = x;
140 }
141
142 static INLINE void fp_force_evall(long double x) {
143 volatile long double y;
144 y = x;
145 }
146 XE_LIB int fpclassify(double x);
147
148#define isfinite(x) ((fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE))
149#define isnormal(x) (fpclassify(x) == FP_NORMAL)
150#define isnan(x) (fpclassify(x) == FP_NAN)
151#define isinf(x) (fpclassify(x) == FP_INFINITE)
152
153#define FORCE_EVAL(x) \
154 do { \
155 if (sizeof(x) == sizeof(float)) { \
156 _KePrint("Evaluating float \r\n"); \
157 fp_force_evalf(x); \
158 } else if (sizeof(x) == sizeof(double)) { \
159 _KePrint("FORCE EVAL double \r\n"); \
160 fp_force_eval(x); \
161 } else { \
162 _KePrint("Force eval long \r\n"); \
163 fp_force_evall(x); \
164 } \
165 } while (0)
166
167 XE_LIB double ceil(double);
168 XE_LIB float ceilf(float x);
169 XE_LIB double cos(double);
170 XE_LIB float acosf(float x);
171 XE_LIB float cosf(float);
172 XE_LIB double fabs(double);
173 XE_LIB float fabsf(float);
174 XE_LIB double floor(double);
175 XE_LIB float floorf(float);
176 XE_LIB double fmod(double, double);
177 XE_LIB double modf(double, double*);
178 XE_LIB float fmodf(float x, float y);
179 XE_LIB double pow(double, double);
180 XE_LIB double sin(double);
181 XE_LIB float sinf(float);
182 XE_LIB double sqrt(double);
183 XE_LIB float sqrtf(float x);
184 XE_LIB double tan(double);
185 XE_LIB float tanf(float);
186 XE_LIB float atanf(float x);
187 XE_LIB float atan2f(float y, float x);
188 XE_LIB double frexp(double x, int* exp);
189 XE_LIB float roundf(float x);
190 XE_LIB float fmaxf(float a, float b);
191 XE_LIB float fminf(float a, float b);
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif
#define INLINE
Definition _xeneva.h:62
#define XE_LIB
Definition _xeneva.h:55
#define XE_EXTERN
Definition _xeneva.h:50
void * memset(void *Dest, int Value, ACPI_SIZE Count)
Definition utclib.c:346
unsigned int uint32_t
Definition acefiex.h:163
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
float exp(float x)
Definition audioCtrl.cpp:53
XE_LIB double frexp(double x, int *exp)
Definition math.cpp:297
XE_LIB double pow(double, double)
Definition math.cpp:173
XE_LIB double sqrt(double)
Definition math.cpp:267
XE_LIB double tan(double)
Definition math.cpp:285
XE_LIB double floor(double)
Definition math.cpp:140
XE_LIB double fabs(double)
Definition math.cpp:126
XE_LIB double cos(double)
Definition math.cpp:62
XE_LIB int fpclassify(double x)
Definition math.cpp:320
XE_LIB float fabsf(float)
Definition math.cpp:133
XE_LIB double fmod(double, double)
Definition math.cpp:150
XE_LIB float atan2f(float y, float x)
Definition atan2f.cpp:35
XE_LIB float fminf(float a, float b)
Definition math.cpp:377
XE_LIB float fmaxf(float a, float b)
Definition math.cpp:373
@ FP_INFINITE
Definition math.h:130
@ FP_SUBNORMAL
Definition math.h:130
@ FP_NORMAL
Definition math.h:130
@ FP_ZERO
Definition math.h:130
@ FP_NAN
Definition math.h:130
XE_LIB float floorf(float)
Definition math.cpp:145
XE_LIB double sin(double)
Definition math.cpp:190
XE_LIB double modf(double, double *)
Definition math.cpp:162
XE_LIB float atanf(float x)
Definition atanf.cpp:25
XE_LIB float sqrtf(float x)
Definition math.cpp:293
XE_LIB float tanf(float)
Definition math.cpp:289
XE_LIB double ceil(double)
Definition math.cpp:52
XE_LIB float roundf(float x)
Definition roundf.cpp:15
XE_LIB float fmodf(float x, float y)
Definition fmodf.cpp:10
XE_LIB float sinf(float)
Definition math.cpp:222
XE_LIB float ceilf(float x)
Definition ceilf.cpp:3
XE_LIB float cosf(float)
Definition math.cpp:94
XE_LIB float acosf(float x)
Definition acosf.cpp:45
Definition math.h:60
double d
Definition math.h:61
uint64_t i
Definition math.h:62
Definition math.h:55
uint32_t i
Definition math.h:57
float f
Definition math.h:56