Skip to content

Commit d63d33e

Browse files
askastitvaheinezen
authored andcommitted
Add atan2 to FixedPoint
1 parent bd06a25 commit d63d33e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

copying.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ _the openage authors_ are:
150150
| Munawar Hafiz | munahaf | munawar dawt hafiz à gmail dawt com |
151151
| Md Ashhar | ashhar | mdashhar01 à gmail dawt com |
152152
| Fábio Barkoski | fabiobarkoski | fabiobarkoskii à gmail dawt com |
153+
| Astitva Kamble | askastitva | astitvakamble5 à gmail dawt com |
153154

154155
If you're a first-time committer, add yourself to the above list. This is not
155156
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016-2018 the openage authors. See copying.md for legal info.
1+
// Copyright 2016-2023 the openage authors. See copying.md for legal info.
22

33
#include "fixed_point.h"
44

@@ -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)