Why aren't there standard traits for mathematical functions?
In addition to the existing Add/Mul/Div/Sub traits, I feel like we also need traits for:
- Trigonometry functions
- Powers
- Logarithms
- One/zero values
- Constants such as π and e
- etc
With these it would be much easier to write generic math code and implement your own numerical types.
I'm currently using Float from num_traits, and I find it very poorly designed. Here are the main issues that come to mind:
- It groups all the math functions in to one \massive\ trait, focring you to write an impl for every operation.
- It requries the implementation of other traits including
ToPrimitive,NumCastandfrom_str_radix - But \worst of all\, it has a
fromwhich clashes with the defaultFromtrait!!! This makes having constants in generic functions extremely verbose. It makes generic programming a pain.
I heard the num_traits crate was taken out of the standard library, and... I can see why. But why don't they replace it with something better?
I plan to implement this myself, and will share what I come up with.