Specification of rational numbers format:
In rational plugin, n==32.
Rational number logically consists of:
n-bit signed integer numerator
n-bit unsigned integer denominator
Where sign of numerator is sign of whole rational number.
There are three types of rational numbers:
1. Non-Zero
numerator != 0
denominator != 0
gcd (abs(numerator), denominator) == 1
2. Zero
numerator == 0
denominator == 1
3. Not-A-Number
numerator == 0
denominator == 0
All other numbers are invalid, and result of any computations
with them is undefined. Rational numbers plugin must convert,
on input parsing, all invalid numbers to valid ones,
and must not allow any invalid number to appear as
result of computations.
Conversion tables:
1. Converted to Non-Zero
Invalid Number:
numerator != 0
denominator != 0
gcd (abs(numerator), denominator) != 1
Conversion algorithm:
numerator /= gcd (abs(numerator), denominator)
denominator /= gcd (abs(numerator), denominator)
2. Converted to Zero
Invalid Number:
numerator == 0
denominator != 0
denominator != 1
Conversion algorithm:
denominator = 1
3. Converted to Not-A-Number
Invalid Number:
numerator != 0
denominator == 0
Conversion algorithm:
numerator = 1
Result of any computation that includes Not-A-Number is Not-A-Number.
If and only if the result cannot fit into rational number format due to
overflow, it Not-A-Number is returned.
Rational numbers plugin must assure that correct result is returned
even if there could be overflow somewhere during computations.
This usually can be achieved by using twice as many bits in internal
computations than are be used in external representation.