Skip to content

Conversation

@moiseev
Copy link
Contributor

@moiseev moiseev commented Jan 13, 2017

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!

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>
@moiseev
Copy link
Contributor Author

moiseev commented Jan 13, 2017

@swift-ci Please test and merge

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.

@swift-ci swift-ci merged commit 4135426 into swiftlang:master Jan 13, 2017
@moiseev moiseev deleted the sqrt branch January 13, 2017 19:31
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