-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Name what ln_gamma does #114754
Conversation
The previous description omitted some important details.
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
/// Natural logarithm of the absolute value of the gamma function | ||
/// | ||
/// The integer part of the tuple indicates the sign of the gamma function. |
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 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:
/// 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.)
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.
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.
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 omitted the period on the initial line because it's not actually a complete sentence, nor does it need to be.
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 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.
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 |
I still think this should say *how* the integer part of the tuple encodes the sign.
|
…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
The previous description omitted some important details.