I'm creating a numeric type called BigNum which is meant to be a really expandable BCD. In the process, I'm overloading most/all of the normal numeric operators. My main question is, do I need to overload each operator for each built-in numeric type (long, ulong, int, uint, short, ushort, byte, sbyte, float, double, decimal), or can I just overload it for double/decimal and have the system coerce the other types behind the scenes?

Edit: I'm also wondering if having the system coerce to double (if indeed this is viable) will maintain accuracy with whole numbers.

有帮助吗?

解决方案

You should provide overloads for all the types you intend to support to avoid unnecessary conversions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top