Compare commits

...

4 Commits

Author SHA1 Message Date
jLynx 2a38f386ab Update version.txt 2022-12-29 15:35:54 +13:00
jLynx 079a0506a4 Update past_version.txt 2022-12-29 15:35:45 +13:00
Brumi-2021 e8ad86cc94 Merge pull request #768 from rusty-labs/sin_function_180_fix
#755 fix, sin_f32 fails at 180
2022-12-28 16:34:38 +01:00
rusty.labs e69c9bbc7b #755 fix, sin_f32 fails at 180
#755 fix, sin_f32 returns incorrect result at 180 degrees, clean up
2022-12-28 01:13:42 -05:00
3 changed files with 12 additions and 16 deletions
+1 -1
View File
@@ -1 +1 @@
v1.5.3
v1.5.4
+1 -1
View File
@@ -1 +1 @@
v1.5.4
v1.6.0
+10 -14
View File
@@ -35,11 +35,9 @@ w = numpy.arange(length, dtype=numpy.float64) * (2 * numpy.pi / length)
v = numpy.sin(w)
print(v)
*/
constexpr size_t sine_table_f32_period_log2 = 8;
constexpr size_t sine_table_f32_period = 1 << sine_table_f32_period_log2;
constexpr uint32_t sine_table_f32_index_mask = sine_table_f32_period - 1;
constexpr uint16_t sine_table_f32_period = 256;
static constexpr std::array<float, sine_table_f32_period + 1> sine_table_f32 { {
static constexpr std::array<float, sine_table_f32_period + 2> sine_table_f32{
0.00000000e+00, 2.45412285e-02, 4.90676743e-02,
7.35645636e-02, 9.80171403e-02, 1.22410675e-01,
1.46730474e-01, 1.70961889e-01, 1.95090322e-01,
@@ -125,24 +123,22 @@ static constexpr std::array<float, sine_table_f32_period + 1> sine_table_f32 { {
-2.42980180e-01, -2.19101240e-01, -1.95090322e-01,
-1.70961889e-01, -1.46730474e-01, -1.22410675e-01,
-9.80171403e-02, -7.35645636e-02, -4.90676743e-02,
-2.45412285e-02, 0.00000000e+00,
} };
-2.45412285e-02, 0.00000000e+00, 0.00000000e+00
};
inline float sin_f32(const float w) {
constexpr float normalize = 1.0 / (2 * pi);
const float x = w * normalize;
const int32_t x_int = std::floor(x);
const float x_frac = x - x_int;
const float x = w / (2 * pi); // normalization
const float x_frac = x - std::floor(x); // [0, 1]
const float n = x_frac * sine_table_f32_period;
const int32_t n_int = static_cast<uint32_t>(n) & sine_table_f32_index_mask;
const uint16_t n_int = static_cast<uint16_t>(n);
const float n_frac = n - n_int;
const float p0 = sine_table_f32[n_int + 0];
const float p0 = sine_table_f32[n_int];
const float p1 = sine_table_f32[n_int + 1];
const float diff = p1 - p0;
const float result = p0 + n_frac * diff;
const float result = p0 + n_frac * diff; // linear interpolation
return result;
}