The num_traits API, but in prefix notation

On crates.io On docs.rs

What is this?

If you're trying to do scientific computing in Rust, and you can't get used to mathematical functions like sin() or cos() being postfix methods, this crate may be for you!

It provides free function versions of the trait methods of the num traits, so that you can easily do things like sin(x) + 3*ln(y).

Each trait's methods are exposed as an module of free functions, named after a snake_case version of the trait's name, and it only takes a couple of use clauses to go from there to using the above syntax in your math expressions.

Only a one-line summary of each method's documentations is provided, please refer to the corresponding trait method's documentation in num_traits for the full details of each function's API contract.

Note that one advantage of the num_traits' trait-based approach over free functions is that trait methods gracefully handle namespace collisions. Whereas with this crate, you will be the one responsible for use-ing the right methods for a given task. For what it's worth, this is why programming languages with prefix numerical methods usually also support method overloading, which Rust could not support as it would break the kind of advanced type inference that all Rustaceans are used to enjoy.

API coverage

This crate generally opts for maximal coverage of the num traits, except in the following circumstances:

If you find a num trait functionality which is neither exposed by this crate nor covered by the above list, this is likely an oversight from my part, please ping me about it.

I am also willing to reconsider any point of the above policy if someone manages to make a good argument against it. Issues are welcome!

License

This crate is distributed under the terms of the MPLv2 license. See the LICENSE file for details.

More relaxed licensing (Apache, MIT, BSD...) may also be negociated, in exchange of a financial contribution. Contact me for details at knightsofni AT gmx DOTCOM.