blob: 318a76c7d615f3da0500367315f37d5fea5da32e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#pragma once
#define NUMBER_FLOAT 1
#define NUMBER_LIBFIX 2
#define NUMBER_FPM 3
#define NUMBER_ALIAS NUMBER_FPM
#if NUMBER_ALIAS == NUMBER_LIBFIX
#include "libfixmath/libfixmath/fixmath.h"
#elif NUMBER_ALIAS == NUMBER_FPM
#include "fpm/include/fpm/fixed.hpp"
#include "fpm/include/fpm/math.hpp"
#endif
namespace Phy2D
{
#if NUMBER_ALIAS == NUMBER_FLOAT
typedef float fixed;
#define NUMBER_MAX (FLT_MAX)
#define NUMBER_MIN (FLT_MIN)
#define SQRT(a) (sqrt((a)))
#define SIN(a) (sin((a)))
#define COS(a) (cos((a)))
#define PI (3.1415925f)
#elif NUMBER_ALIAS == NUMBER_LIBFIX
// 同时一定要开启内联函数扩展,否则执行效率会非常低
typedef Fix16 fixed;
#define NUMBER_MAX (fix16_maximum)
#define NUMBER_MIN (fix16_minimum)
#define SQRT(a) ((a).sqrt())
#define SIN(a) ((a).sin())
#define COS(a) ((a).cos())
#define PI (fix16_pi)
#elif NUMBER_ALIAS == NUMBER_FPM
template <typename T>
struct Limits {};
template <>
struct Limits<fpm::fixed_16_16>
{
static constexpr bool is_signed() noexcept { return true; }
static constexpr int digits() noexcept { return 31; }
static constexpr int max_digits10() noexcept { return 5 + 5; }
static constexpr int min_exponent() noexcept { return -15; }
static constexpr int max_exponent() noexcept { return 15; }
static constexpr int min_exponent10() noexcept { return -4; }
static constexpr int max_exponent10() noexcept { return 4; }
static constexpr fpm::fixed_16_16 min() noexcept { return fpm::fixed_16_16::from_raw_value(-2147483647 - 1); }
static constexpr fpm::fixed_16_16 max() noexcept { return fpm::fixed_16_16::from_raw_value(2147483647); }
};
template <>
struct Limits<fpm::fixed_24_8>
{
static constexpr bool is_signed() noexcept { return true; }
static constexpr int digits() noexcept { return 31; }
static constexpr int max_digits10() noexcept { return 7 + 3; }
static constexpr int min_exponent() noexcept { return -7; }
static constexpr int max_exponent() noexcept { return 23; }
static constexpr int min_exponent10() noexcept { return -2; }
static constexpr int max_exponent10() noexcept { return 6; }
static constexpr fpm::fixed_24_8 min() noexcept { return fpm::fixed_24_8::from_raw_value(-2147483647 - 1); }
static constexpr fpm::fixed_24_8 max() noexcept { return fpm::fixed_24_8::from_raw_value(2147483647); }
};
template <>
struct Limits<fpm::fixed_8_24>
{
static constexpr bool is_signed() noexcept { return true; }
static constexpr int digits() noexcept { return 31; }
static constexpr int max_digits10() noexcept { return 3 + 8; }
static constexpr int min_exponent() noexcept { return -23; }
static constexpr int max_exponent() noexcept { return 7; }
static constexpr int min_exponent10() noexcept { return -7; }
static constexpr int max_exponent10() noexcept { return 2; }
static constexpr fpm::fixed_8_24 min() noexcept { return fpm::fixed_8_24::from_raw_value(-2147483647 - 1); }
static constexpr fpm::fixed_8_24 max() noexcept { return fpm::fixed_8_24::from_raw_value(2147483647); }
};
typedef fpm::fixed_16_16 fixed;
#define NUMBER_MAX (Limits<fixed>::max())
#define NUMBER_MIN (Limits<fixed>::min())
#define SQRT(a) (fpm::sqrt((a)))
#define SIN(a) (fpm::sin((a)))
#define COS(a) (fpm::cos((a)))
#define PI (fixed::pi())
#endif
}
|