-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
Now that square root is being propoerly inlined and optimized away, it is safe to deprecate these two constants in favor of a Swiftier API. Fixes: <rdar://problem/30003973>
@swift-ci Please test and merge |
@@ -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() |
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.
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.)
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.
That would require an import, whereas 2.squareRoot()
is available without any imports and thus is more local.
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 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.
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.
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
.
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'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?
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 was planning on doing a follow-up patch to handle a few more of these macros. We can discuss there.
Now that square root is being propoerly inlined and optimized away, it
is safe to deprecate these two constants in favor of a Swiftier API.
Fixes: rdar://problem/30003973
Thanks @stephentyrone for #6769!