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

Name what ln_gamma does #114754

Merged
merged 1 commit into from
Aug 25, 2023
Merged

Conversation

workingjubilee
Copy link
Contributor

The previous description omitted some important details.

The previous description omitted some important details.
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 12, 2023
Comment on lines +981 to +983
/// Natural logarithm of the absolute value of the gamma function
///
/// The integer part of the tuple indicates the sign of the gamma function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be okay to merge this as-is, but since it's worth explaining why this sign is useful in the first place, I decided to write up an explanation about how this can be used to compute the complex-valued logarithm from the returned value:

Suggested change
/// Natural logarithm of the absolute value of the gamma function
///
/// The integer part of the tuple indicates the sign of the gamma function.
/// Natural logarithm of the absolute value of the gamma function.
///
/// Since the gamma function can be negative, its natural logarithm could
/// be complex-valued and thus not normally representable. While the
/// standard library doesn't offer any means to deal with complex values,
/// this function still offers the real part of the resulting complex
/// logarithm, which is equivalent to the logarithm of the absolute value
/// of the input.
///
/// To help construct the full complex value, the sign of the computed gamma
/// function before taking the natural logarithm is offered as a second
/// return value, which can trivially be converted into an imaginary part
/// by multiplying by [`f32::PI`].

(Note that I say "an imaginary part" since the complex logarithm may add additional factors of 2pi, but that's not super important to say here. So, I am still remaining correct while not worrying anyone about it who doesn't really care.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also worth mentioning if you do like this and want to copy it to the f64 version, you should change the link to f32::PI to f64::PI.

This also is an indication of why returning the sign as a float instead of an int might be preferable, as discussed on the issue.

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 omitted the period on the initial line because it's not actually a complete sentence, nor does it need to be.

Copy link
Member

Choose a reason for hiding this comment

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

I think "the sign [...] is offered as a second return value" needs explanation, i.e. -- this returns 1 on positive (or 0) gamma values and -1 on negative values.

Also while we are at it, do we want to change the sign to be represented as an f32? Otherwise it will require somewhat awkward explicit conversion back to a float type.

@thomcc
Copy link
Member

thomcc commented Aug 25, 2023

I don't know that we need an explanation of what ln_gamma is useful for. I guess I would accept it, but I don't think this needs to block landing this improvement.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 25, 2023

📌 Commit 90dc2f8 has been approved by thomcc

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 25, 2023
@RalfJung
Copy link
Member

RalfJung commented Aug 25, 2023 via email

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 25, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#114754 (Name what ln_gamma does)
 - rust-lang#115081 (Allow overwriting ExpnId for concurrent decoding)
 - rust-lang#115151 (Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI)
 - rust-lang#115169 (remove some unnecessary ignore-debug clauses)
 - rust-lang#115190 (Add comment to the push_trailing function)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b88849d into rust-lang:master Aug 25, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 25, 2023
@workingjubilee workingjubilee deleted the gamma-ray-logger branch August 25, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants