-
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
Merged
stephentyrone
merged 2 commits into
swiftlang:master
from
stephentyrone:deprecate-float-constants
Jan 14, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
@_exported import Darwin // Clang module | ||
|
||
public let MAP_FAILED = | ||
UnsafeMutableRawPointer(bitPattern: -1)! as UnsafeMutableRawPointer! | ||
|
||
// Constants defined by <math.h> | ||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") | ||
public let M_PI = Double.pi | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.") | ||
public let M_PI_2 = Double.pi / 2 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.") | ||
public let M_PI_4 = Double.pi / 4 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.") | ||
public let M_SQRT2 = 2.squareRoot() | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.") | ||
public let M_SQRT1_2 = 0.5.squareRoot() | ||
|
||
// Constants defined by <float.h> | ||
@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, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]: | ||
% if type == "Float80": | ||
#if arch(i386) || arch(x86_64) | ||
% end | ||
// Where does the 1 come from? C counts the usually-implicit leading | ||
// significand bit, but Swift does not. Neither is really right or wrong. | ||
@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.") | ||
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 (following IEEE 754) considers the | ||
// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP | ||
// as well. | ||
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.") | ||
public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.") | ||
public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.") | ||
public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.") | ||
public let ${prefix}_EPSILON = ${type}.ulpOfOne | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.") | ||
public let ${prefix}_MIN = ${type}.leastNormalMagnitude | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.") | ||
public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude | ||
|
||
% if type == "Float80": | ||
#endif | ||
% end | ||
%end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
@_exported import SwiftGlibc // Clang module | ||
|
||
public let MAP_FAILED = | ||
UnsafeMutableRawPointer(bitPattern: -1)! as UnsafeMutableRawPointer! | ||
|
||
// Constants defined by <math.h> | ||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") | ||
public let M_PI = Double.pi | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.") | ||
public let M_PI_2 = Double.pi / 2 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.") | ||
public let M_PI_4 = Double.pi / 4 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.") | ||
public let M_SQRT2 = 2.squareRoot() | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.") | ||
public let M_SQRT1_2 = 0.5.squareRoot() | ||
|
||
// Constants defined by <float.h> | ||
@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, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]: | ||
% if type == "Float80": | ||
#if arch(i386) || arch(x86_64) | ||
% end | ||
// Where does the 1 come from? C counts the usually-implicit leading | ||
// significand bit, but Swift does not. Neither is really right or wrong. | ||
@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.") | ||
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 (following IEEE 754) considers the | ||
// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP | ||
// as well. | ||
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.") | ||
public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.") | ||
public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1 | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.") | ||
public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.") | ||
public let ${prefix}_EPSILON = ${type}.ulpOfOne | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.") | ||
public let ${prefix}_MIN = ${type}.leastNormalMagnitude | ||
|
||
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.") | ||
public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude | ||
|
||
% if type == "Float80": | ||
#endif | ||
% end | ||
%end |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
|
||
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) | ||
import Darwin | ||
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) | ||
import Glibc | ||
#endif | ||
|
||
_ = FLT_RADIX // expected-warning {{is deprecated}} | ||
|
||
_ = FLT_MANT_DIG // expected-warning {{is deprecated}} | ||
_ = FLT_MIN_EXP // expected-warning {{is deprecated}} | ||
_ = FLT_MAX_EXP // expected-warning {{is deprecated}} | ||
_ = FLT_MAX // expected-warning {{is deprecated}} | ||
_ = FLT_EPSILON // expected-warning {{is deprecated}} | ||
_ = FLT_MIN // expected-warning {{is deprecated}} | ||
_ = FLT_TRUE_MIN // expected-warning {{is deprecated}} | ||
|
||
_ = DBL_MANT_DIG // expected-warning {{is deprecated}} | ||
_ = DBL_MIN_EXP // expected-warning {{is deprecated}} | ||
_ = DBL_MAX_EXP // expected-warning {{is deprecated}} | ||
_ = DBL_MAX // expected-warning {{is deprecated}} | ||
_ = DBL_EPSILON // expected-warning {{is deprecated}} | ||
_ = DBL_MIN // expected-warning {{is deprecated}} | ||
_ = DBL_TRUE_MIN // expected-warning {{is deprecated}} | ||
|
||
#if arch(i386) || arch (x86_64) | ||
_ = LDBL_MANT_DIG // expected-warning {{is deprecated}} | ||
_ = LDBL_MIN_EXP // expected-warning {{is deprecated}} | ||
_ = LDBL_MAX_EXP // expected-warning {{is deprecated}} | ||
_ = LDBL_MAX // expected-warning {{is deprecated}} | ||
_ = LDBL_EPSILON // expected-warning {{is deprecated}} | ||
_ = LDBL_MIN // expected-warning {{is deprecated}} | ||
_ = LDBL_TRUE_MIN // expected-warning {{is deprecated}} | ||
#endif |
File renamed without changes.
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.
Shouldn't it be surrounded by
#if arch(i386) || arch(x86_64) ... #endif
?