7#ifndef MFRAME_EEC25F8B_68C8_45FC_A820_3773DB4D7EF7
8#define MFRAME_EEC25F8B_68C8_45FC_A820_3773DB4D7EF7
15#include "./../lang/NonInstantiable.h"
57 virtual ~Maths(
void)
override =
default;
93 static double acos(
double x);
118 static double atan2(
double y,
double x);
126 static double cos(
double x);
142 static double sin(
double x);
167 static double frexp(
double x,
int *exponent);
176 static double ldexp(
double x,
int exponent);
184 static double log(
double x);
203 static double modf(
double x,
double *integer);
214 static double pow(
double x,
double y);
275 static double fmod(
double x,
double y);
285 static constexpr int abs(
int a) {
286 return (a < 0) ? ~a : a;
297 static constexpr long abs(
long a) {
298 return (a < 0) ? (a * (-1)) : a;
309 static constexpr float abs(
float a) {
310 return (a < 0) ? (a * (-1)) : a;
320 if (value & 0x00000003UL)
return (value & 0xFFFFFFF4UL) + 4;
332 if (value & 0x00000007UL)
return (value & 0xFFFFFFF8UL) + 8;
348 static inline uint32 floorPowerOf2(uint32 value) {
350 while (r <= value) r <<= 1;
365 static inline uint32 ceilPowerOf2(uint32 value) {
367 while (r < value) r <<= 1;
382 static inline uint32 floorShiftCount(uint32 value) {
384 while ((1U << r) <= value) r++;
399 static inline uint32 ceilShiftCount(uint32 value) {
401 while ((1U << r) < value) r++;
412 static constexpr int ceil(
int dividend,
int divisor) {
413 return (dividend + (divisor - 1)) / divisor;
423 static constexpr uint32
ceil(uint32 dividend, uint32 divisor) {
424 return (dividend + (divisor - 1)) / divisor;
434 static constexpr uint32
min(uint32 a, uint32 b) {
435 return ((a) < (b) ? (a) : (b));
445 static constexpr int min(
int a,
int b) {
446 return ((a) < (b) ? (a) : (b));
456 static constexpr uint32
max(uint32 a, uint32 b) {
457 return ((a) > (b) ? (a) : (b));
467 static constexpr int max(
int a,
int b) {
468 return ((a) > (b) ? (a) : (b));
478 static constexpr uint32
log2(uint32 n, uint32 p = 0) {
479 return (n <= 1) ? p :
log2(n >> 1, p + 1);
數學運算工具類別
Definition Maths.h:36
static double pow(double x, double y)
返回 x 的 y 次方
static double asin(double x)
返回x的正弦弧線弧度。
static double ldexp(double x, int exponent)
返回 x 乘以 2 的 exponent 次方。
static constexpr int max(int a, int b)
回傳兩個整數中的較大值。
Definition Maths.h:467
static constexpr int ceil(int dividend, int divisor)
向上取整(整數版本)。
Definition Maths.h:412
static constexpr uint32 ceil(uint32 dividend, uint32 divisor)
向上取整(無符號整數版本)。
Definition Maths.h:423
static constexpr int min(int a, int b)
回傳兩個整數中的較小值。
Definition Maths.h:445
virtual ~Maths(void) override=default
Destroy the Maths object.
static uint32 align32bit(uint32 value)
32位元位址對齊。
Definition Maths.h:319
static double acos(double x)
返回x的反餘弦弧度。
static double atan2(double y, double x)
返回y/x的反正切值(弧度),以判別正確象限。
static double log(double x)
返回x的自然對數(以E為底)。
static double atan(double x)
返回x的反正切值,以弧度為單位。
static double cos(double x)
返回弧度角x的餘弦值。
static double ceil(double x)
向上取整
static constexpr uint32 min(uint32 a, uint32 b)
回傳兩個無符號整數中的較小值。
Definition Maths.h:434
static double tanh(double x)
返回x的雙曲正切值。
static double sin(double x)
返回弧度角x的正弦值。
static double fmod(double x, double y)
取餘數
static double sqrt(double x)
計算 x 的平方根
static double sinh(double x)
返回x的雙曲正弦值。
static double log10(double x)
返回x的常用對數(以10為底)。
static double fabs(double x)
計算 x 的絕對值 (雙精度)
static constexpr uint32 log2(uint32 n, uint32 p=0)
計算無符號整數的二進位對數(以2為底)。
Definition Maths.h:478
static constexpr int abs(int a)
回傳整數的絕對值。如果參數為非負數,則直接回傳該值;若為負數則回傳其相反數。
Definition Maths.h:285
static double floor(double x)
向下取整
static uint32 align64bit(uint32 value)
64位元位址對齊。
Definition Maths.h:331
static constexpr float abs(float a)
回傳浮點數的絕對值。如果參數為非負數,則直接回傳該值;若為負數則回傳其相反數。
Definition Maths.h:309
static constexpr long abs(long a)
回傳長整數的絕對值。如果參數為非負數,則直接回傳該值;若為負數則回傳其相反數。
Definition Maths.h:297
static double modf(double x, double *integer)
分解浮點值 x 為整數與小數部分
static double frexp(double x, int *exponent)
返回x的尾數與指數,滿足 x = 尾數 * 2^指數。
static float fabsf(float x)
計算 x 的絕對值 (單精度)
static double cosh(double x)
返回x的雙曲餘弦值。
static constexpr uint32 max(uint32 a, uint32 b)
回傳兩個無符號整數中的較大值。
Definition Maths.h:456
Definition NonInstantiable.h:29
Definition Appendable.h:23