Method powi not found on a generic type

Hello all,

I am trying to convert a function to generic types. I have got many errors, I tried solving some but I am unable to figure out some mistakes.

The code is available here.

  • In the code to compare a float and the type T I am converting the type to T using 2. as T, Is there any alternative to that.
  • I use powi and powf methods to raise it, but it doesn't work. Is there any trait I need to add to my generic type to work.

Any other inputs are welcome.

Thank you.

You might want to take a look at the num crate. It includes a variety of traits for dealing with generic number types.

1 Like

There's no trait for this in stdlib. Use traits from the num crate as @chrisd mentioned, or define your trait with all the methods you need, and implement it for the types you support (such implementations can usually be deduplicated with the help of macros).

1 Like