Add math constants corresbonding to util/math_constants.h for FixedPoint#1607
Merged
heinezen merged 2 commits intoSFTtech:masterfrom Dec 4, 2023
Merged
Add math constants corresbonding to util/math_constants.h for FixedPoint#1607heinezen merged 2 commits intoSFTtech:masterfrom
util/math_constants.h for FixedPoint#1607heinezen merged 2 commits intoSFTtech:masterfrom
Conversation
util/math_constant.h for FixedPoint
util/math_constant.h for FixedPointutil/math_constants.h for FixedPoint
Contributor
Author
|
Have added a full set of math constants for FixedPoint. |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).