SayoriOS  0.3.3
math.h
1 #pragma once
2 
3 #include "common.h"
4 
5 #define ABS(a) ((a) >= 0 ? (a) : -(a))
6 
7 #define MIN(a, b) \
8 ({ __typeof__ (a) _a = (a); \
9  __typeof__ (b) _b = (b); \
10  _a < _b ? _a : _b; })
11 
12 #define MAX(a, b) \
13 ({ __typeof__ (a) _a = (a); \
14  __typeof__ (b) _b = (b); \
15  _a > _b ? _a : _b; })
16 
17 union intfloat32 {
18  uint32_t i;
19  float f;
20 };
21 
22 union intfloat64 {
23  uint64_t i;
24  double f;
25 };
26 
27 static inline float int2float(uint32_t i) {
28  union intfloat32 v;
29  v.i = i;
30  return v.f;
31 }
32 
33 static inline double int2double(uint64_t i) {
34  union intfloat64 v;
35  v.i = i;
36  return v.f;
37 }
38 
39 static inline bool is_nan(float value) {
40  union intfloat32 value_union;
41  value_union.f = value;
42 
43  int exponent = (value_union.i >> 23) & 0xFF;
44  int fraction = value_union.i & 0x7FFFFF;
45 
46  return exponent == 0xFF && fraction != 0;
47 }
48 
49 static inline bool is_inf(float value) {
50  union intfloat32 value_union;
51  value_union.f = value;
52 
53  unsigned int exponent = (value_union.i >> 23) & 0xFF;
54  unsigned int fraction = value_union.i & 0x7FFFFF;
55 
56  return (exponent == 0xFF) && (fraction == 0);
57 }
58 
59 static inline double floor(double x) {
60  int intPart = (int)x;
61 
62  return intPart - (x < 0 && x != intPart);
63 }
64 
65 static inline double ceil(double x) {
66  int intPart = (int)x;
67 
68  return intPart + (x > 0 && x != intPart);
69 }
70 
71 static inline double fabs(double x) {
72  return (x < 0) ? -x : x;
73 }
74 
75 #define PI 3.141592653589793
76 
77 #define ASIN_STEPS 6000
78 #define ATAN_STEPS 6000
79 
80 #define NAN int2float(0x7fc00000)
81 #define INFINITY int2float(0x7f800000)
82 
83 double deg2rad(double);
84 double rad2deg(double);
85 
86 size_t fac(size_t);
87 
88 double sin(double);
89 double cos(double);
90 double tan(double);
91 
92 double pow(double base, double exponent);
93 size_t ipow(size_t val, size_t exp);
94 
95 double trapezoidal_rule(double (*f)(double), double a, double b, unsigned int steps);
96 
97 double log(double x);
98 double exp(double x);
99 
100 double asin(double x);
101 double acos(double x);
102 double atan(double x);
103 
104 double sqrt(double x);
105 double cbrt(double x);
106 double modf(double value, double* intPart);
107 // static inline double sqrt(double x) {
108 // return pow(x, 0.5);
109 // }
110 
111 // static inline double cbrt(double x) {
112 // return pow(x, 1/3);
113 // }
Основные определения ядра