Timo Paulssen <[email protected]> wrote:
> 
> Can you give us the .perl of $!total_interest, $interests and 
> $interests.Rat? (perhaps even the .nude, too?)
> 
> On 29/10/15 10:31, Kamil Kułaga (via RT) wrote:
> > # New Ticket Created by  "Kamil Kułaga"
> > # Please include the string:  [perl #126485]
> > # in the subject line of all future correspondence about this issue.
> > # <URL: https://rt.perl.org/Ticket/Display.html?id=126485 >
> >
> >
> > I've tried to substitute numeric with Rat (and the switch to FatRat) but 
> > found some issues in type checking. Errors does not occur on simple 
> > examples so I provide whole code.
> >
> >        $!total_interest += $interests.Rat;
> >
> > Normally it is not a problem to += two rats but here it becomes a problem.

It's impossible to say what's going on without more source code than that, 
but please note that basic Rat arithmetic is not guaranteed to result in a 
Rat.  It is explicitly spec'd that if arithmetic would cause the 
denominator of a Rat to exceed what can be stored in an uint64, the 
operation will return a Num instead.

    http://design.perl6.org/S02.html#Numeric_Types

If you want the denominator to grow endlessly instead, you want to use 
FatRat, which is there for exactly this reason.  (Though I think mixing 
FatRats and Nums will return a Num -- while it is certainly possible to 
exactly convert a Num to a FatRat, as far as I know no one has implemented 
that code for us yet.)

Note, however, that Rats are probably a bad choice for mortgage 
calculations anyway.  No one in the "real world" is more precise than a 
Num there, so all you could possibly do is introduce discrepancies between 
your calculations and more standard mortgage systems.

--Sol

-- 
Sol Foster: [email protected]

Reply via email to