SFTtech / openage

Free (as in freedom) open source clone of the Age of Empires II engine 🚀
http://openage.dev
Other
12.51k stars 1.11k forks source link

Add math constants corresbonding to `util/math_constants.h` for FixedPoint #1607

Closed AyiStar closed 7 months ago

AyiStar commented 7 months ago

To add pure fixed-point math functions (issue #1543), I found it would be better add some math constants (issue #1544). So here is a WIP PR which adds first two important constants, E and PI. The solution is as follows.

(1) In "fixed_point.h", I add two staic functions which return E and PI, respectively, referrng to the implementation of the fpm library.

(2) The from_fixedpoint() function is fixed to avoid the situation of narrowing warning/error furing compilation when the fractional_bits of created FixedPoint constant object is smaller than the predefined one, i.e., 61.

(3) By the way, I also amend the comment doc of safeshift function.

(4) In "fixed_point_test.cpp", I add some tests which utilizes the constants defined in "math_constant.h" for comparison. I also test constant under different precisions (see TestTypeShort in the tests).

AyiStar commented 7 months ago

Have added a full set of math constants for FixedPoint.