`typed_float` math libraries?

Hi.

In our team, we've been using typed_float very happily.

But I'm looking at some code from my colleagues and it feels like we could benefit from working with a unit-of-measurement library and/or a linear algebra library.

But I'd lot to be able to keep the nice properties of typed_float (such as the NoN-NaN-NeSs and type-encoded sign)

Any suggestions? a brief search on https://lib.rs doesn't yield much.

If by “linear algebra library” you mean “points, vectors, transformations”, then a generic library like euclid should be able to work on your typed floats. (I do this myself, though I haven’t used typed_float.)

However, if you mean things more like solving linear equations or inverting matrices, that nontrivial arithmetic can very often produce NaN or infinities, and so there is, in a sense, no need for compatibility: you have to fall back to plain f32/f64 and then check that the result is not NaN.

(typed_float author here)

Thank you for that heartwarming feedback.

Sadly no. It require the Float trait, from the num-trait lib: Float in num_traits::float - Rust

Last I checked, it couldn't be implemented for typed_floats, because that trait requied that the output type is the same as the input for some operations, which is incompatible with typed_floats. I could investigate if num-trait could be improved without breaking changes, and if they are open to that kind of changes.

I doubt it's possible without breaking changes, simply because users of where T: Float can currently rely on the ops keeping the same type.

The euclid crate also requires that on its own in many places, e.g. Rect<T>::area.