-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Remove most free-standing numeric functions and implement Interpolate trait #6986
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
Conversation
For the moment this includes only a lerp method. This trait should be expanded to be more comprehensive in the future.
Implements - Linear - Cosine - Smooth (Based on Smooth Step) - Barycentric - Hermite - Cubic - Catmull-Rom They are implemented using Horner's rule, which should be the fastest assuming that we cannot get any parallelism. At some later date we can see if we could optimize them for super-scalar processors. TODO: Add documentation, tests and make the implementation generic.
It just tests edge cases, but the actual results should vary with the availability of fast FMA so I am not testing them right now.
…ng delegated f64/f32 functions These should now be covered by methods in the numeric traits
The original tests were not accurate in double-precision, but I must have forgotten to run the tests in double-precision so I never noticed that. The new tests are designed to be accurate in all sensible IEEE 754 precisions, including half-precision.
I r+'d this but I'm not at all confident that all these obscure interpolation functions are appropriate for std, nor that they make sense as a trait. In the future please try to put different features in different pull requests. |
why remove free-standing numeric functions? They are the most intuitive definition of numerical operation. A numerical function does not act on a number (it does not change it), but it maps it to an element form the same or different set. An expression like 2.0f32.sin() is ugly, hard to read and would probably prevent a lot of people (including me) to ever use rust for numerical applications. |
I agree with you @Casorati partially. Syntax-wise I think we should allow for the But I also think it is very important to remove the current free-standing numeric functions. Currently there are at least three different The sane way to implement the numeric functions is to
Ps. @bjz, could you split up this PR into two? The two groups of changes are completely orthogonal. |
The method vs free-standing call thing is part of uniform method calls, which we intend to fix generally. Not sure about schedule. |
Then I think the changes should include the fix instead of forcing a temporary syntax change in existing code. @JensNockert How can a generic version of a function like sin be defined in rust? |
@JensNockert sure thing! I think this has been a good discussion anyway. :) |
As part of #4819, this commit removes most of the free-standing wrapper functions from the numeric modules. It also removes the re-exports of the delegated intrinsic and cmath functions in
std::{float, f32, f64}
.What does this mean from a user perspective? Most of the functions you normally use are now covered by methods in the numeric trait hierarchy. For example,
f32::sin(2.0)
would now be written as2.0f32.sin()
, orint::min(1, 2)
as1i.min(&2)
(unfortunately the explicit type suffix is needed because Rust can't infer the type).@jensnockert has also added an
Interpolate
trait tostd::num
implemented forfloat
,f64
andf32
. This adds the following associated functions:In addition, I have also added the error functions to
std::num::Real
: