You should provide overloads for all the types you intend to support to avoid unnecessary conversions.
Overloading Operators for Numeric Types in C#
-
15-06-2023 - |
Question
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.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow