Skip to content
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

Tracking issue for {f32, f64}::copysign #58046

Closed
SimonSapin opened this issue Feb 1, 2019 · 25 comments
Closed

Tracking issue for {f32, f64}::copysign #58046

SimonSapin opened this issue Feb 1, 2019 · 25 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

These methods landed in October 2018 in #55169 without a tracking issue.

impl f32 {
    pub fn copysign(self, y: f32) -> f32 {}
}
impl f64 {
    pub fn copysign(self, y: f64) -> f64 {}
}

CC @raphlinus

@SimonSapin SimonSapin added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Feb 1, 2019
@SimonSapin
Copy link
Contributor Author

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Feb 1, 2019

Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Feb 1, 2019
@nikic
Copy link
Contributor

nikic commented Feb 1, 2019

I've mentioned this on the PR before: a.copysign(b) is not very clear on whether the sign of a is applied to b or the sign of b is applied to a. A different name like a.with_sign_of(b) could remove the ambiguity, at the expense of using less standard terminology. (Re-raising this here for visibility, but I think this function is used rarely enough that it ultimately doesn't matter.)

@alexcrichton
Copy link
Member

@rfcbot concern naming

formally registering @nikic's concern

@SimonSapin
Copy link
Contributor Author

I did see that comment in the PR, but found the next comments convincing:

I'm going to suggest sticking with standard terminology, because I think the target user is much more likely to be studying or adapting numerical algorithms from other languages, rather than than writing Rust-only numerical algorithms. Also I think when studying asm output (especially wasm), it reduces the translation, understanding that copysign in the source should translate into the copysign intrinsic.

I think keeping the standard name copysign makes sense. And you've kept the order of arguments: a.copysign(b) matches copysign(a, b).

@raphlinus
Copy link
Contributor

Sorry for not creating the tracking issue myself, I had it in my list of things to do but didn't get around to it. I don't have much to add; if this were a "de novo" function, then the name change would make sense, but I think consistency with existing usage carries weight.

@Centril
Copy link
Contributor

Centril commented Feb 2, 2019

This seems fine since it can be replaced with logic that doesn't use an intrinsic if necessary. However, i n future, please include the lang team when exposing intrinsics.

@Ravenslofty
Copy link

I think changing the name to be clearer has precedent; we have ptr::copy_nonoverlapping not ptr::memcpy to better explain the invariant, as one example.

I think a.with_sign_of(b) looks good in code, but f32::with_sign_of in documentation looks like a constructor (see Vec::with_capacity for example).

How about a.copy_sign_to(b)/ f32::copy_sign_to?

@raphlinus
Copy link
Contributor

I have two issues with copy_sign_to. First, it seems like the order of arguments is reversed, which I think can be confusing. Second, the "to" makes it sound more like it's mutating.

@Ravenslofty
Copy link

Ravenslofty commented Feb 4, 2019 via email

@crlf0710
Copy link
Member

crlf0710 commented Feb 4, 2019

copy_sign_from ?

@joshtriplett
Copy link
Member

This seems to have gotten stuck for a while, and it looks like the only blocker is the function name.

Many libraries and developers already describe this function as copysign. While we certainly can change the name if we find it sufficiently unclear or error-prone (such as the example for memcpy, which leads to common problems in C), it seems like people already know this function as copysign. Changing the name would make it harder for people to translate algorithms to Rust or write Rust code given familiarity with other sources of floating-point algorithms.

I would also suggest that we generally seem to do operations this way around, taking the argument and applying it with the operation to self, rather than taking self and applying it with the operation to the argument. Sub::sub takes the argument and subtracts it from self, for instance. So reordering the arguments seems especially error-prone.

I think this is a case where the change will cause more confusion than the established name will.

@nikic
Copy link
Contributor

nikic commented Mar 18, 2019

I looks like the consensus is in favor of copysign(), and I think think the combination of this being both an established concept and a somewhat rarely used function make that a reasonable choice.

Please feel free to mark the concern as resolved (I don't think I can do that myself...)

@SimonSapin
Copy link
Contributor Author

I think @alexcrichton needs to mark it resolved?

@rfcbot resolve naming

@alexcrichton
Copy link
Member

@rfcbot resolve naming

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Mar 18, 2019
@rfcbot
Copy link

rfcbot commented Mar 18, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Mar 18, 2019
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Mar 28, 2019
@rfcbot
Copy link

rfcbot commented Mar 28, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot removed the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Mar 28, 2019
@jethrogb
Copy link
Contributor

I guess I'm a little late with this comment but I think the name should be copy_sign, following Rust naming convention for separating words.

Centril added a commit to Centril/rust that referenced this issue Mar 29, 2019
…Sapin

Stablize {f32,f64}::copysign().

Stablization PR for rust-lang#55169/rust-lang#58046. Please check if i'm doing it correctly. Is 1.35.0 good to go?
@SimonSapin
Copy link
Contributor Author

I personally don’t have an opinion on this. (The name without a space has precedent and might help in search engine results.) But since the stabilization PR has merged in the 1.35 cycle, if we rename we should do so this or next week.

@Centril
Copy link
Contributor

Centril commented Mar 29, 2019

My preference is for copy_sign over copysign; seems we could redirect confused users from copysign using some #[rustc_on_misspelled = "copysign"]... iirc @estebank had some idea of that kind?

@jethrogb
Copy link
Contributor

I'm assuming the method name suggestion logic would find copy_sign automatically if someone tries copysign? The documentation search for sure can already do this: https://doc.rust-lang.org/std/?search=copynonoverlapping

@cwhakes
Copy link
Contributor

cwhakes commented Apr 5, 2019

Maybe too late for bikeshedding, but could the parameter y be renamed to sign? That could alleviate @nikic's concerns. It could cause confusion if someone isn't expecting it to sign to be a f32, but in every case I can think of, the type annotation will be next to the name.

@Centril
Copy link
Contributor

Centril commented Apr 5, 2019

Maybe too late for bikeshedding, but could the parameter y be renamed to sign?

@cwhakes The parameter's name is not part of the stable interface so you can just file a PR for that and I'll review it.

@tesuji
Copy link
Contributor

tesuji commented May 30, 2019

{f32,f64}::copysign had been stabilized in 1.35.0. Should we close this tracking issue?

@Centril
Copy link
Contributor

Centril commented May 30, 2019

Yep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests