Would something like
class Complex[T: Numeric](real: T, imag: T)
make sense, instead of writing a Complex class using Double
s, one using Long
s, one using BigInt
s, so that everyone can choose the number type he needs?
How would performance compare to the non-generic approach?
For the moment, Numeric
is not @specialized
. So the generic version using it will suffer from boxing and unboxing and the performances will be greatly reduced. Here is a nice blog post with performance measurments:
http://www.azavea.com/blogs/labs/2011/06/scalas-numeric-type-class-pt-2/
However, you could directly write a @specialized
version of your Complex number class without using Numeric
and get all the benefits.
On a strictly pragmatic point of view, I am not sure to understand what's the usage of a complex number with integer parts...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.