toRational converts floating-point types to rationals with a tolerance epsilon which by default is 1e-8. However, this is an absolute rather than relative value, and currently the code does not even support the case where the floating-point input is less than the tolerance value, simply returning zero:
// Handle this as a special case to make the rest of the code less
// complicated:
if (abs(floatNum) < epsilon)
{
Rational!Int ret;
ret.num = 0;
ret.den = 1;
return ret;
}
Suggested solution: toRational should accept both a relative and absolute tolerance, as with std.math.approxEquals.
toRational
converts floating-point types to rationals with a toleranceepsilon
which by default is1e-8
. However, this is an absolute rather than relative value, and currently the code does not even support the case where the floating-point input is less than the tolerance value, simply returning zero:Suggested solution:
toRational
should accept both a relative and absolute tolerance, as withstd.math.approxEquals
.