Botcraft 26.2
Loading...
Searching...
No Matches
MathsUtilities.cpp
Go to the documentation of this file.
2
3#include <cmath>
4
5
6#if PROTOCOL_VERSION < 774 /* < 1.21.11 */
7namespace
8{
9 constexpr float SIN_SCALE = 10430.378f; /* 65536 / 2 / pi but with less accuracy */
10 constexpr float COS_OFFSET = 16384.0f;
11 constexpr long long int SIN_MASK = 65535L;
12
13 // If profiling shows a bottleneck, replace with the actual 65536 LUT
14 float LUT(const int index)
15 {
16 return static_cast<float>(std::sin(static_cast<double>(index) * 3.141592653589793 * 2.0 / 65536.0));
17 }
18}
19
20float SinLUT(const double d)
21{
22 return LUT(static_cast<int>(static_cast<float>(d) * SIN_SCALE) & SIN_MASK);
23}
24
25float CosLUT(const double d)
26{
27 return LUT(static_cast<int>(static_cast<float>(d) * SIN_SCALE + COS_OFFSET) & SIN_MASK);
28}
29#else
30namespace
31{
32 constexpr double SIN_SCALE = 10430.378350470453; /* 65536 / 2 / pi */
33 constexpr int COS_OFFSET = 16384;
34 constexpr long long int SIN_MASK = 65535L;
35
36 // If profiling shows a bottleneck, replace with the actual 65536 LUT
37 float LUT(const int index)
38 {
39 return static_cast<float>(std::sin(static_cast<double>(index) / SIN_SCALE));
40 }
41}
42
43float SinLUT(const double d)
44{
45 return LUT(static_cast<int>(static_cast<long long>(d * SIN_SCALE) & SIN_MASK));
46}
47
48float CosLUT(const double d)
49{
50 return LUT(static_cast<int>(static_cast<long long>(d * SIN_SCALE + COS_OFFSET) & SIN_MASK));
51}
52#endif
float SinLUT(const double d)
float CosLUT(const double d)