-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added pow function fpm #1621
Added pow function fpm #1621
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this one |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this one |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this one |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -589,6 +589,19 @@ constexpr double hypot(openage::util::FixedPoint<I, F> x, openage::util::FixedPo | |
return x.hypot(y); | ||
} | ||
|
||
template <typename I, unsigned F> | ||
constexpr openage::util::FixedPoint<I, F> pow(openage::util::FixedPoint<I, F> base, double exponent) { | ||
// Handle special cases: 0^0, 1^x, x^0 | ||
if (base == 0.0 && exponent == 0.0) { | ||
return openage::util::FixedPoint<I, F>::quiet_NaN(); // Undefined; return NaN | ||
} else if (base == 1.0 || exponent == 0.0) { | ||
Comment on lines
+595
to
+597
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why compare to doubles in the if conditions when we could compre to fixed point values instead? |
||
return openage::util::FixedPoint<I, F>::from_raw_value(1); | ||
} | ||
double log_base = std::log(base.get_raw_value()); | ||
double result = exponent * log_base; | ||
Comment on lines
+600
to
+601
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pure fixed-point math functions should avoid any floating point arithmetic. Avoiding the floating point rounding erros is the point of using fp math after all. |
||
return openage::util::FixedPoint<I, F>::from_raw_value(std::exp(result)); | ||
} | ||
|
||
template <typename I, unsigned F> | ||
struct hash<openage::util::FixedPoint<I, F>> { | ||
constexpr size_t operator()(const openage::util::FixedPoint<I, F> &n) const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file would need to be removed