rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
732 stars 135 forks source link

`Float` should imply `MulAdd`, instead of having own `mul_add` method. #206

Open zakarumych opened 3 years ago

zakarumych commented 3 years ago

In generic code I would like Float bound to be enough to use it where MulAdd is expected given there is Float::mul_add, so trait can always be implemented. Maybe even put it under NumOps since Mul + Add is enough to implement this trait, with fusion for types that support it and as a * b + c for other types.

cuviper commented 3 years ago

Maybe even put it under NumOps since Mul + Add is enough to implement this trait,

This only works if all of the RHS and Output types are the same.

Anyway, it would be a breaking change to require the relatively new MulAdd on the older traits, but you can easily create your own trait NewNum: Sized + NumOps + MulAdd<Output = Self> {}.