Acknowledging that 'FatRat' is current name for above 'Ratio' ...

pugs-comm...@feather.perl6.nl wrote:
-For applications that really need arbitrary precision denominators
-as well as numerators, C<Ratio> may be used, which is defined as C<Int/Int>.
+For applications that really need arbitrary precision denominators as
+well as numerators at the cost of performance, C<Ratio> may be used,
+which is stored as C<Int/Int>, that is, as arbitrary precision in
+both parts.  There is no literal form for a C<Ratio>, so it must
+be constructed using C<Ratio.new($nu,$de)>.  In general, only math
+operators with at least one C<Ratio> argument will return another
+C<Ratio>, to prevent accidental promotion of reasonably fast C<Rat>
+values into arbitrarily slow C<Ratio> values.

Given the above, if one wants to construct a full-precision rational value in terms of 3 Int values analogous to a mantissa and radix and exponent, what is the best way to write it in Perl 6?

For example, say I want the following expression to result in a FatRat because presumably that's the only type which will represent the result value exactly:

  45207196 * 10 ** -37

How should that be spelled out in terms of 3 integers?

And note that a decimal-specific answer isn't what I want, since I want something that would also work for this:

  45207196 * 11 ** -37

Any thoughts?

Basically where I'm coming from here is the idea that any rational can also be expressed as 3 integers like the above, not just the numerator/denominator pair; the 3 integers are advantages both for being efficient with common pathological cases such as very large or very small rationals with a small amount of precision, such as the above, as well as for exactly reflecting the concept of a radix-agnostic floating-point number.

Thank you. -- Darren Duncan

Reply via email to