-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add erf
and erfc
to f32
and f64
#89
Comments
So this does come up a fair bit in numeric code, is already in our |
While |
Yeah, my gut feeling would be that Anyway, I'm a bit torn here, and ended up writing too much). Here's why I kinda think we shouldn't: The big argument against these applies to basically any new special numeric function: it increases the number of functions that Rust code is expected to provide on numeric types. This has (IMO) a semi-large impact, applying both to code in the ecosystem and in the stdlib. For example, if we add this, it would be reasonable for users to want it to also be supported on:
IMO this doesn't mean that we can't add new functions to the float types (the cost of this for one or two functions is not unthinkable), just that we are justified being fairly picky about it. So, do Overall, I'd probably lean towards no (even though I've wanted them before). They can be easily provided by a crate, and I do think they're pretty niche (even if I do find them more useful than, say, An interesting metric might be "how many people depend on CC @workingjubilee (who cares about numbers too and may have stronger feelings), and @cuviper (who maintains Footnotes
|
I assume
I don't think this should be a blocker for |
This is actually my secondary motivation for raising this. The decision on whether or not Rust will aim to match the scope of the C99 mathematics library would factor into my decision on when to bump the version number of my custom floating point crate |
@thomcc - the issue template here says "Once this issue is filed the libs-api team will review open proposals in its weekly meeting." but I see from the Zulip logs that ACPs aren't actually included in the meetings. In this case, what is the process for advancing here, either to proceed with an implementation or (as I guess is more realistic given the sentiments in this thread) get some kind of official "we're not going to do this". |
We only just got to the point where we are about to start reviewing these in periodic meetings, sorry. Part of this was blocked on #118 |
Ship it. Please open a tracking issue and file a PR adding these as unstable methods. |
Feel free to open a tracking issue for this and open a PR to add it as unstable. Thanks! |
This proposal was accepted, but no tracking issue is listed and I could not find one. I briefly considered opening a stub tracking issue, but I am not convinced that would not be counter-productive. Is there anything to do here to preserve the decision or is it prefereable to let the decision expire (as it were) and retake it if it comes up in the future? |
Someone just needs to open a tracking issue and contribute an initial implementation. |
Opened a tracking issue so we have it rust-lang/rust#136321 |
Proposal
Problem statement
The Gauss error function
erf
occurs relatively frequently in statistics and physics and is part of the C99 standard library. Currently theerf
function and the relatederfc
are only accessible in Rust via external crates (e.g. libm).Motivation, use-cases
The error function$x$ is defined as:
erf
on a real numberSpecific cases for
erf
:The related complementary error function
erfc
is defined as:Specific cases for
erfc
:These functions cannot be simply expressed in terms of the other Rust std library floating-point functions. The function is available in the standard libraries of C since C99 and Python since Python 3.2.
The primary use case for$\Phi$ of the normal (Gaussian) distribution, which occurs frequently in statistics. The relationship, expressed in terms of
erf
is its relation to the cumulative distribution functionerf
on f64 is:or in terms of
erfc
as:This link to the normal distribution results in
erf
(and functions derived fromerf
) occurring fairly often in mathematical/statistical code. Together with the ongoing proposal for implementing the gamma function (rust-lang/rfcs#864), this brings Rust's standard library closer to implementing the full range of mathematical functions in C99.Solution sketches
For C99-compatible implementations of the C standard library, the process would involve exposing the library functions
erf
anderfc
(forf64
), anderff
anderfcf
(forf32
).Otherwise there exists a Rust implementation in the libm crate, which would provide a basis in case of any future plans to move the floating point mathematical functions into
core
.An alternative approach might be to stabilise the cumulative normal distribution function$\Phi$ directly, though this would require additional processing of the C standard library output and possibly be less familiar than having
erf
available directly given its inclusion in the standard libraries of other languages.Links and related work
erf
,erff
,erfl
: https://en.cppreference.com/w/c/numeric/math/erferfc
,erfcf
,erfcl
: https://en.cppreference.com/w/c/numeric/math/erfcerf
,erfc
: https://docs.python.org/3/library/math.html#special-functionserf
/erfc
: https://github.com/rust-lang/libm/blob/master/src/math/erf.rserff
/erfcf
: https://github.com/rust-lang/libm/blob/master/src/math/erff.rsWhat happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.
The text was updated successfully, but these errors were encountered: