-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[APFloat][NFC]extract fltSemantics::isRepresentableBy to header
#122636
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
Merged
HerrCai0907
merged 1 commit into
main
from
users/ccc01-12-_apfloat_extract_fltsemantics_isrepresentableby_to_header
Jan 13, 2025
+14
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,14 +125,6 @@ struct fltSemantics { | |
|
|
||
| /* Whether this semantics can represent signed values */ | ||
| bool hasSignedRepr = true; | ||
|
|
||
| // Returns true if any number described by this semantics can be precisely | ||
| // represented by the specified semantics. Does not take into account | ||
| // the value of fltNonfiniteBehavior. | ||
| bool isRepresentableBy(const fltSemantics &S) const { | ||
| return maxExponent <= S.maxExponent && minExponent >= S.minExponent && | ||
| precision <= S.precision; | ||
| } | ||
| }; | ||
|
|
||
| static constexpr fltSemantics semIEEEhalf = {15, -14, 11, 16}; | ||
|
|
@@ -290,6 +282,12 @@ const fltSemantics &APFloatBase::x87DoubleExtended() { | |
| } | ||
| const fltSemantics &APFloatBase::Bogus() { return semBogus; } | ||
|
|
||
| bool APFloatBase::isRepresentableBy(const fltSemantics &A, | ||
| const fltSemantics &B) { | ||
| return A.maxExponent <= B.maxExponent && A.minExponent >= B.minExponent && | ||
| A.precision <= B.precision; | ||
|
Member
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. I think this should take into account |
||
| } | ||
|
|
||
| constexpr RoundingMode APFloatBase::rmNearestTiesToEven; | ||
| constexpr RoundingMode APFloatBase::rmTowardPositive; | ||
| constexpr RoundingMode APFloatBase::rmTowardNegative; | ||
|
|
@@ -5527,7 +5525,7 @@ APFloat::opStatus APFloat::convertToInteger(APSInt &result, | |
| double APFloat::convertToDouble() const { | ||
| if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEdouble) | ||
| return getIEEE().convertToDouble(); | ||
| assert(getSemantics().isRepresentableBy(semIEEEdouble) && | ||
| assert(isRepresentableBy(getSemantics(), semIEEEdouble) && | ||
| "Float semantics is not representable by IEEEdouble"); | ||
| APFloat Temp = *this; | ||
| bool LosesInfo; | ||
|
|
@@ -5541,7 +5539,7 @@ double APFloat::convertToDouble() const { | |
| float128 APFloat::convertToQuad() const { | ||
| if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEquad) | ||
| return getIEEE().convertToQuad(); | ||
| assert(getSemantics().isRepresentableBy(semIEEEquad) && | ||
| assert(isRepresentableBy(getSemantics(), semIEEEquad) && | ||
| "Float semantics is not representable by IEEEquad"); | ||
| APFloat Temp = *this; | ||
| bool LosesInfo; | ||
|
|
@@ -5555,7 +5553,7 @@ float128 APFloat::convertToQuad() const { | |
| float APFloat::convertToFloat() const { | ||
| if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEsingle) | ||
| return getIEEE().convertToFloat(); | ||
| assert(getSemantics().isRepresentableBy(semIEEEsingle) && | ||
| assert(isRepresentableBy(getSemantics(), semIEEEsingle) && | ||
| "Float semantics is not representable by IEEEsingle"); | ||
| APFloat Temp = *this; | ||
| bool LosesInfo; | ||
|
|
||
Oops, something went wrong.
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.
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.
What's your use case for this function? Given that this function does not take into account
fltNonfiniteBehavior,hasZero,hasSignedRepr, I'm wondering how useful it is in practice. (I'm also wondering, why it does not take into accountfltNonfiniteBehavior.)Uh oh!
There was an error while loading. Please reload this page.
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.
For the usecase of this functions. I want to warn for implicit loss of accuracy when floating point conversation happened in compiler frontend type systems.
It needs API to detect floating point type compatibility.
The original usage of this function is in
APFloat::convertTo*series function to check compatibility.At least for these cases, I think it only needs to check the floating point number compatibility in normal range instead to consider
NaNandInf.Since this patch more like a refactor, I don't want to change the meaning of this API. Actually I try to add these requirements and test break.
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.
As an NFC change, this looks good to me.
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.
If we are changing the semantics of this, can we do that as a separate PR?