|
7 | 7 |
|
8 | 8 | #include "kernel.h" |
9 | 9 |
|
| 10 | +static inline double rr_nan(void) { |
| 11 | + union { uint64_t u; double d; } v = { 0x7ff8000000000000ULL }; // NaN |
| 12 | + return v.d; |
| 13 | +} |
| 14 | + |
10 | 15 | /** |
11 | 16 | * @brief Raise base to the power of exp |
12 | 17 | * |
@@ -58,3 +63,111 @@ double tan(double rads); |
58 | 63 | * @return double calculated square root of `x` |
59 | 64 | */ |
60 | 65 | double sqrt(double x); |
| 66 | + |
| 67 | +/** |
| 68 | + * @brief Returns the absolute value of a floating point number. |
| 69 | + * |
| 70 | + * @param x The input value. |
| 71 | + * @return The absolute value of x (|x|). |
| 72 | + */ |
| 73 | +double fabs(double x); |
| 74 | + |
| 75 | +/** |
| 76 | + * @brief Rounds a floating point number down to the nearest integer value. |
| 77 | + * |
| 78 | + * @param x The input value. |
| 79 | + * @return The largest integer value less than or equal to x, as a double. |
| 80 | + */ |
| 81 | +double floor(double x); |
| 82 | + |
| 83 | +/** |
| 84 | + * @brief Computes the floating-point remainder of x / y. |
| 85 | + * |
| 86 | + * The result is x - n * y, where n is the integer quotient of x / y, |
| 87 | + * truncated toward zero. |
| 88 | + * |
| 89 | + * @param x Dividend. |
| 90 | + * @param y Divisor (must not be zero). |
| 91 | + * @return The remainder of x divided by y. |
| 92 | + */ |
| 93 | +double fmod(double x, double y); |
| 94 | + |
| 95 | +/** |
| 96 | + * @brief Rounds a floating-point value up to the nearest integer. |
| 97 | + * |
| 98 | + * @param x Input value. |
| 99 | + * @return The smallest integer value not less than x. |
| 100 | + */ |
| 101 | +double ceil(double x); |
| 102 | + |
| 103 | +/** |
| 104 | + * @brief Rounds a floating-point value to the nearest integer. |
| 105 | + * |
| 106 | + * Values halfway between two integers are rounded away from zero. |
| 107 | + * |
| 108 | + * @param x Input value. |
| 109 | + * @return The nearest integer as a double. |
| 110 | + */ |
| 111 | +double round(double x); |
| 112 | + |
| 113 | +/** |
| 114 | + * @brief Computes the arc tangent of y/x using the signs of both arguments |
| 115 | + * to determine the correct quadrant of the result. |
| 116 | + * |
| 117 | + * @param y y-coordinate (numerator). |
| 118 | + * @param x x-coordinate (denominator). |
| 119 | + * @return The angle in radians between -PI and PI. |
| 120 | + */ |
| 121 | +double atan2(double y, double x); |
| 122 | + |
| 123 | +/** |
| 124 | + * @brief Computes the arc tangent of x (inverse tangent). |
| 125 | + * |
| 126 | + * The result is in radians, between -PI/2 and PI/2. |
| 127 | + * |
| 128 | + * @param x The input value. |
| 129 | + * @return The arc tangent of x. |
| 130 | + */ |
| 131 | +double atan(double x); |
| 132 | + |
| 133 | +/** |
| 134 | + * @brief Returns the arc sine (inverse sine) of x. |
| 135 | + * @param x Input value (must be between -1 and 1). |
| 136 | + * @return The arcsin of x in radians. |
| 137 | + */ |
| 138 | +double asin(double x); |
| 139 | + |
| 140 | +/** |
| 141 | + * @brief Returns the arc cosine (inverse cosine) of x. |
| 142 | + * @param x Input value (must be between -1 and 1). |
| 143 | + * @return The arccos of x in radians. |
| 144 | + */ |
| 145 | +double acos(double x); |
| 146 | + |
| 147 | +/** |
| 148 | + * @brief Calculates e raised to the power of x. |
| 149 | + * @param x Exponent. |
| 150 | + * @return e^x. |
| 151 | + */ |
| 152 | +double exp(double x); |
| 153 | + |
| 154 | +/** |
| 155 | + * @brief Computes the natural logarithm (ln) of x. |
| 156 | + * @param x Input value (must be > 0). |
| 157 | + * @return ln(x). |
| 158 | + */ |
| 159 | +double log(double x); |
| 160 | + |
| 161 | +/** |
| 162 | + * @brief Converts radians to degrees. |
| 163 | + * @param radians Value in radians. |
| 164 | + * @return Value in degrees. |
| 165 | + */ |
| 166 | +double deg(double radians); |
| 167 | + |
| 168 | +/** |
| 169 | + * @brief Converts degrees to radians. |
| 170 | + * @param degrees Value in degrees. |
| 171 | + * @return Value in radians. |
| 172 | + */ |
| 173 | +double rad(double degrees); |
0 commit comments