Skip to content

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

Merged
merged 2 commits into from
Jan 14, 2017
Merged

Mark several C macros imported from <float.h> as deprecated. #6796

merged 2 commits into from
Jan 14, 2017

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Jan 13, 2017

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

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).
@stephentyrone stephentyrone requested a review from moiseev January 13, 2017 22:35
@stephentyrone
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@moiseev moiseev left a 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 :shipit:.

@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"]:
Copy link
Contributor

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
Copy link
Contributor

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 "
Copy link
Contributor

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}}
Copy link
Contributor

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?

@moiseev
Copy link
Contributor

moiseev commented Jan 13, 2017

Also, could you please mention the radar (rdar://problem/27871465) in the commit message?

@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@stephentyrone stephentyrone merged commit 6ff95da into swiftlang:master Jan 14, 2017
@stephentyrone stephentyrone deleted the deprecate-float-constants branch January 14, 2017 02:33
@gparker42
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants