mFrame
載入中...
搜尋中...
無符合項目
Maths.h
1
7#ifndef MFRAME_EEC25F8B_68C8_45FC_A820_3773DB4D7EF7
8#define MFRAME_EEC25F8B_68C8_45FC_A820_3773DB4D7EF7
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15#include "./../lang/NonInstantiable.h"
16
17/* ***************************************************************************************
18 * Namespace
19 */
20namespace ufm::lang {
21 class Maths;
22} // namespace ufm::lang
23
24/* ***************************************************************************************
25 * Class Math
26 */
27
37 /* *************************************************************************************
38 * Subclass
39 */
40
41 /* *************************************************************************************
42 * Variable
43 */
44
45 /* *************************************************************************************
46 * Abstract Method
47 */
48
49 /* *************************************************************************************
50 * Construct Method
51 */
52 protected:
57 virtual ~Maths(void) override = default;
58
59 /* *************************************************************************************
60 * Operator Method
61 */
62
63 /* *************************************************************************************
64 * Override Method
65 */
66
67 /* *************************************************************************************
68 * Public Method
69 */
70
71 /* *************************************************************************************
72 * Protected Method
73 */
74
75 /* *************************************************************************************
76 * Private Method
77 */
78
79 /* *************************************************************************************
80 * Static Variable
81 */
82
83 /* *************************************************************************************
84 * Static Method
85 */
86 public:
93 static double acos(double x);
94
101 static double asin(double x);
102
109 static double atan(double x);
110
118 static double atan2(double y, double x);
119
126 static double cos(double x);
127
134 static double cosh(double x);
135
142 static double sin(double x);
143
150 static double sinh(double x);
151
158 static double tanh(double x);
159
167 static double frexp(double x, int *exponent);
168
176 static double ldexp(double x, int exponent);
177
184 static double log(double x);
185
192 static double log10(double x);
193
203 static double modf(double x, double *integer);
204
214 static double pow(double x, double y);
215
224 static double sqrt(double x);
225
234 static double ceil(double x);
235
244 static double fabs(double x);
245
254 static float fabsf(float x);
255
264 static double floor(double x);
265
275 static double fmod(double x, double y);
276
285 static constexpr int abs(int a) {
286 return (a < 0) ? ~a : a;
287 }
288
297 static constexpr long abs(long a) {
298 return (a < 0) ? (a * (-1)) : a;
299 }
300
309 static constexpr float abs(float a) {
310 return (a < 0) ? (a * (-1)) : a;
311 }
312
319 static inline uint32 align32bit(uint32 value) {
320 if (value & 0x00000003UL) return (value & 0xFFFFFFF4UL) + 4;
321
322 return value;
323 }
324
331 static inline uint32 align64bit(uint32 value) {
332 if (value & 0x00000007UL) return (value & 0xFFFFFFF8UL) + 8;
333
334 return value;
335 }
336
348 static inline uint32 floorPowerOf2(uint32 value) {
349 uint32 r = 1;
350 while (r <= value) r <<= 1;
351 return r >> 1;
352 }
353
365 static inline uint32 ceilPowerOf2(uint32 value) {
366 uint32 r = 1;
367 while (r < value) r <<= 1;
368 return r;
369 }
370
382 static inline uint32 floorShiftCount(uint32 value) {
383 uint32 r = 0;
384 while ((1U << r) <= value) r++;
385 return (r - 1);
386 }
387
399 static inline uint32 ceilShiftCount(uint32 value) {
400 uint32 r = 0;
401 while ((1U << r) < value) r++;
402 return r;
403 }
404
412 static constexpr int ceil(int dividend, int divisor) {
413 return (dividend + (divisor - 1)) / divisor;
414 }
415
423 static constexpr uint32 ceil(uint32 dividend, uint32 divisor) {
424 return (dividend + (divisor - 1)) / divisor;
425 }
426
434 static constexpr uint32 min(uint32 a, uint32 b) {
435 return ((a) < (b) ? (a) : (b));
436 }
437
445 static constexpr int min(int a, int b) {
446 return ((a) < (b) ? (a) : (b));
447 }
448
456 static constexpr uint32 max(uint32 a, uint32 b) {
457 return ((a) > (b) ? (a) : (b));
458 }
459
467 static constexpr int max(int a, int b) {
468 return ((a) > (b) ? (a) : (b));
469 }
470
478 static constexpr uint32 log2(uint32 n, uint32 p = 0) {
479 return (n <= 1) ? p : log2(n >> 1, p + 1);
480 }
481};
482
483/* ***************************************************************************************
484 * End of file
485 */
486
487#endif /* MFRAME_EEC25F8B_68C8_45FC_A820_3773DB4D7EF7 */
數學運算工具類別
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