There is this problem with C# decimal type:
Console.WriteLine( 1m/3 + 1m/3 == 2m/3 );
False
It can represent numbers exactly only when dividing by 2 or 5, otherwise result could be repeating decimal number.
As mentioned on Stack Overflow before (C# Rational arithmetic), implementing something which stores two decimals, numerator and denominator, and performs multiplications and divisions exactly is quite possible. It can simplify fractions when needed using Euclid's algorithm. Some explicit conversion to double or decimal should also be implemented.
There are some rational quotients implementations presented here and here. There is also a Microsoft Solver Foundation structure Rational.
How decimal
in C# is implemented and is it possible to copy this implementation and modify it to handle repeating decimal
s ?
There are some trials related to repeating decimals presented in SO answers here and here