Skip to content

Commit 1078cbb

Browse files
committed
update
1 parent e0865c7 commit 1078cbb

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

cp-algo/math/cvector.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ namespace cp_algo::math::fft {
6565
} else if(n / 4 < pre_evals) {
6666
return evalp[n / 4];
6767
} else {
68-
return polar(1., std::numbers::pi / (ftype)std::bit_floor(n) * (ftype)eval_arg(n));
68+
return polar<ftype>(1., std::numbers::pi / (ftype)std::bit_floor(n) * (ftype)eval_arg(n));
6969
}
7070
}
7171
static constexpr std::array<point, 32> roots = []() {
7272
std::array<point, 32> res;
7373
for(size_t i = 2; i < 32; i++) {
74-
res[i] = polar(1., std::numbers::pi / (1ull << (i - 2)));
74+
res[i] = polar<ftype>(1., std::numbers::pi / (1ull << (i - 2)));
7575
}
7676
return res;
7777
}();
@@ -203,7 +203,7 @@ namespace cp_algo::math::fft {
203203
std::array<point, pre_evals> res = {};
204204
res[0] = 1;
205205
for(size_t n = 1; n < pre_evals; n++) {
206-
res[n] = polar(1., std::numbers::pi * ftype(eval_args[n]) / ftype(4 * std::bit_floor(n)));
206+
res[n] = polar<ftype>(1., std::numbers::pi * ftype(eval_args[n]) / ftype(4 * std::bit_floor(n)));
207207
}
208208
return res;
209209
}();

cp-algo/util/simd.hpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@ namespace cp_algo {
1717
return a < 0 ? -a : a;
1818
}
1919

20-
// https://stackoverflow.com/a/77376595
21-
// works for ints in (-2^51, 2^51)
22-
static constexpr dx4 magic = dx4() + (3ULL << 51);
23-
[[gnu::always_inline]] inline i64x4 lround(dx4 x) {
24-
return i64x4(x + magic) - i64x4(magic);
25-
}
26-
[[gnu::always_inline]] inline dx4 to_double(i64x4 x) {
27-
return dx4(x + i64x4(magic)) - magic;
28-
}
29-
3020
[[gnu::always_inline]] inline dx4 round(dx4 a) {
31-
#ifdef __AVX2__
32-
return _mm256_round_pd(a, _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
33-
#else
34-
return __builtin_convertvector(lround(a), dx4);
35-
#endif
21+
return dx4{
22+
std::nearbyint(a[0]),
23+
std::nearbyint(a[1]),
24+
std::nearbyint(a[2]),
25+
std::nearbyint(a[3])
26+
};
3627
}
3728

3829
[[gnu::always_inline]] inline u64x4 montgomery_reduce(u64x4 x, u64x4 mod, u64x4 imod) {

verify/poly/wildcard.test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void semicorr(auto &a, auto &b) {
2222
}
2323

2424
auto is_integer(auto a) {
25-
static const double eps = 1e-8;
25+
static const ftype eps = 1e-8;
2626
return cp_algo::abs(imag(a)) < eps
2727
&& cp_algo::abs(real(a) - cp_algo::round(real(a))) < eps;
2828
}
@@ -33,7 +33,7 @@ string matches(string const& A, string const& B, char wild = '*') {
3333
if(!init) {
3434
init = true;
3535
for(int i = 0; i < 128; i++) {
36-
project[0][i] = cp_algo::polar(1., (ftype)cp_algo::random::rng());
36+
project[0][i] = cp_algo::polar<ftype>(1., (ftype)cp_algo::random::rng());
3737
project[1][i] = conj(project[0][i]);
3838
}
3939
}

0 commit comments

Comments
 (0)