Why aren't there standard traits for mathematical functions?

92 points ilia3101

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:

  1. It groups all the math functions in to one \massive\ trait, focring you to write an impl for every operation.
  2. It requries the implementation of other traits including ToPrimitive, NumCast and from_str_radix
  3. But \worst of all\, it has a from which clashes with the default From trait!!! 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.