Skip to content

Deprecating M_SQRT2 and M_SQRT1_2 #6786

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 1 commit into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdlib/public/Platform/Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be cleaner to use sqrt(2) instead here? (The free function sqrt is defined by Platform; it's possibly less Swifty but more familiar to people.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require an import, whereas 2.squareRoot() is available without any imports and thus is more local.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If M_SQRT2 is available, they have by definition imported Platform so sqrt is available. I don't think that this is a big deal, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. Right. It is quite possible to simply recommend 2 variants in the message...
On the other hand... If we establish a certain usage pattern with these recommendations, people will hopefully start using it everywhere, regardless of import Platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more inclined to leave the recommendation as is, unless anyone has strong objections.
BTW, is there a reason why sqrt is not available without any imports?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on doing a follow-up patch to handle a few more of these macros. We can discuss there.


@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.")
public let M_SQRT1_2 = 0.5.squareRoot()
6 changes: 6 additions & 0 deletions stdlib/public/Platform/Glibc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ public let M_PI_2 = Double.pi / 2

@available(swift, deprecated: 3.0, message: "Please use '.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()
3 changes: 3 additions & 0 deletions test/MathConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ import Glibc
_ = M_PI // expected-warning {{is deprecated}}
_ = M_PI_2 // expected-warning {{is deprecated}}
_ = M_PI_4 // expected-warning {{is deprecated}}

_ = M_SQRT2 // expected-warning {{is deprecated}}
_ = M_SQRT1_2 // expected-warning {{is deprecated}}