-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Mark several C macros imported from <float.h> as deprecated. #6796
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
Mark several C macros imported from <float.h> as deprecated. #6796
Conversation
These macros all have straightforward replacements in terms of static properties on FloatingPoint or BinaryFloatingPoint. It is necessary to add 1 in a few places because of differences between how C and Swift count significand bits and normalize the significand, but this is expected to have minimal impact on code in practice (and when it does have impact, using the Swift definition is generally simpler).
@swift-ci Please test |
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.
A few nitpicks. Overall a .
@available(swift, deprecated: 3.0, message: "Please use 'T.radix' to get the radix of a FloatingPoint type 'T'.") | ||
public let FLT_RADIX = Double.radix | ||
|
||
%for type in ["Float","Double","Float80"]: |
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.
May I suggest:
for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]:
public let ${prefix}_MANT_DIG = ${type}.significandBitCount + 1 | ||
|
||
// Where does the 1 come from? C models floating-point numbers as having a | ||
// significand in [0.5, 1), but Swift (follwing IEEE 754) considers the |
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.
s/follwing/following
|
||
%for type in ["Float","Double","Float80"]: | ||
% prefix = {"Float":"FLT","Double":"DBL","Float80":"LDBL"}[type] | ||
% implicit = "implicit " |
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.
I don't see ${implicit}
being used anywhere. Does it belong in the comment?
|
||
_ = FLT_MANT_DIG // expected-warning {{is deprecated}} | ||
_ = DBL_MANT_DIG // expected-warning {{is deprecated}} | ||
_ = LDBL_MANT_DIG // expected-warning {{is deprecated}} |
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.
Shouldn't it be surrounded by #if arch(i386) || arch(x86_64) ... #endif
?
Also, could you please mention the radar (rdar://problem/27871465) in the commit message? |
@swift-ci please test |
Reverting in #6817. The FloatConstants test is failing on iOS. The test is incorrectly written for architectures that aren't i386 or x86_64; the verifier still expects the long double warnings and (correctly) doesn't get them. |
These macros all have straightforward replacements in terms of static properties on FloatingPoint or BinaryFloatingPoint. It is necessary to add 1 in a few places because of differences between how C and Swift count significand bits and normalize the significand, but this is expected to have minimal impact on code in practice (and when it does have impact, using the Swift definition is generally simpler).
rdar://problem/27871465