Darren Duncan wrote:
Moritz Lenz wrote:
FatRat.new(45207196, 10**37);

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

FatRat.new(45207196, 11**37);

Solomon Foster wrote:
What's your objection to FatRat.new(45207196, 11 ** 37)?

Well, for one thing, that's not the same value. I had a "-37" as the exponent, designating a small non-integer rational value, whereas the FatRat example had flipped this around to "37", not the same value.

Now I'm sure the format you showed looks great, but my concern is, does simply saying this:

  11 ** -37

... result in a FatRat and if not then how do I write "11^-37" in Perl 6 such that the resulting object retains the full precision of the value?

Actually, I realize now what was going on with that suggestion, and that it actually was valid for the case I mentioned, being presumably equal to:

  45207196 * FatRat.new( 1, 11**37 )

However, the ideal situation would be a format I could use unchanged regardless of whether the exponent (-37) is positive or negative.

Unless there is one, it would seem I might have to do this in a generic setting, given 3 integers $mantis, $radix, $exp but $radix is always >= 2:

  $exp < 0 ?? FatRat.new( $mantis, $radix**$exp ) !! $mantis * $radix**$exp

What I think might be ideal though is if the FatRat.new() could be a multi that also has a 3-param variant, so that something like this would work:

  FatRat.new( $mantissa, $radix, $exponent )

I would be clear that this 3-param variant would be 3 integers, including the mantissa, because that guarantees that the new FatRat would be an exact multiple of $radix**$exponent.

-- Darren Duncan

Reply via email to