Skip to content

Commit 1ff9c43

Browse files
committed
Add atan2 to FixedPoint
1 parent e83bb4e commit 1ff9c43

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

copying.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ _the openage authors_ are:
148148
| Zoltán Ács | zoli111 | acszoltan111 à gmail dawt com |
149149
| Trevor Slocum | tslocum | trevor à rocket9labs dawt com |
150150
| Munawar Hafiz | munahaf | munawar dawt hafiz à gmail dawt com |
151+
| Astitva Kamble | askastitva | astitvakamble5 à gmail dawt com |
151152

152153
If you're a first-time committer, add yourself to the above list. This is not
153154
just for legal reasons, but also to keep an overview of all those nicknames.

libopenage/util/fixed_point.h

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)