Skip to content

Commit 285cd2d

Browse files
committed
Add atan2 to FixedPoint
1 parent e83bb4e commit 285cd2d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

libopenage/util/fixed_point.h

+9
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ class FixedPoint {
370370
constexpr double sqrt() {
371371
return std::sqrt(this->to_double());
372372
}
373+
374+
constexpr double atan2(const FixedPoint &n) {
375+
return std::atan2(this->to_double(), n->to_double());
376+
}
373377
};
374378

375379

@@ -481,6 +485,11 @@ constexpr double sqrt(openage::util::FixedPoint<I, F> n) {
481485
return n.sqrt();
482486
}
483487

488+
template <typename I, unsigned F>
489+
constexpr double atan2(openage::util::FixedPoint<I, F> x, openage::util::FixedPoint<I, F> y) {
490+
return x.atan2(y);
491+
}
492+
484493
template <typename I, unsigned F>
485494
constexpr openage::util::FixedPoint<I, F> min(openage::util::FixedPoint<I, F> x, openage::util::FixedPoint<I, F> y) {
486495
return openage::util::FixedPoint<I, F>::from_raw_value(

libopenage/util/fixed_point_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void fixed_point() {
5858
TESTEQUALS_FLOAT((e * 10).to_double(), 108.3 * 10, 1e-7);
5959
TESTEQUALS_FLOAT((e / 10).to_double(), 108.3 / 10, 1e-7);
6060
TESTEQUALS_FLOAT(std::sqrt(e), sqrt(108.3), 1e-7);
61+
TESTEQUALS_FLOAT(std::atan2(e, f), atan2(108.3, -12.4), 1e-7);
6162
TESTEQUALS_FLOAT(std::abs(-e).to_double(), 108.3, 1e-7);
6263
TESTEQUALS_FLOAT(std::hypot(e, f), hypot(108.3, -12.4), 1e-7);
6364
TESTEQUALS_FLOAT(std::min(e, f), -12.4, 1e-7);

0 commit comments

Comments
 (0)