Skip to content

Commit

Permalink
Add atan2 to FixedPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
askastitva committed Oct 20, 2023
1 parent e83bb4e commit 1ff9c43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ _the openage authors_ are:
| Zoltán Ács | zoli111 | acszoltan111 à gmail dawt com |
| Trevor Slocum | tslocum | trevor à rocket9labs dawt com |
| Munawar Hafiz | munahaf | munawar dawt hafiz à gmail dawt com |
| Astitva Kamble | askastitva | astitvakamble5 à gmail dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
9 changes: 9 additions & 0 deletions libopenage/util/fixed_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ class FixedPoint {
constexpr double sqrt() {
return std::sqrt(this->to_double());
}

constexpr double atan2(const FixedPoint &n) {
return std::atan2(this->to_double(), n.to_double());
}
};


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

template <typename I, unsigned F>
constexpr double atan2(openage::util::FixedPoint<I, F> x, openage::util::FixedPoint<I, F> y) {
return x.atan2(y);
}

template <typename I, unsigned F>
constexpr openage::util::FixedPoint<I, F> min(openage::util::FixedPoint<I, F> x, openage::util::FixedPoint<I, F> y) {
return openage::util::FixedPoint<I, F>::from_raw_value(
Expand Down
1 change: 1 addition & 0 deletions libopenage/util/fixed_point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void fixed_point() {
TESTEQUALS_FLOAT((e * 10).to_double(), 108.3 * 10, 1e-7);
TESTEQUALS_FLOAT((e / 10).to_double(), 108.3 / 10, 1e-7);
TESTEQUALS_FLOAT(std::sqrt(e), sqrt(108.3), 1e-7);
TESTEQUALS_FLOAT(std::atan2(e, f), atan2(108.3, -12.4), 1e-7);
TESTEQUALS_FLOAT(std::abs(-e).to_double(), 108.3, 1e-7);
TESTEQUALS_FLOAT(std::hypot(e, f), hypot(108.3, -12.4), 1e-7);
TESTEQUALS_FLOAT(std::min(e, f), -12.4, 1e-7);
Expand Down

0 comments on commit 1ff9c43

Please sign in to comment.