Skip to content
Permalink
Browse files

Normalize ZDRs on Rational creation

  • Loading branch information...
zoffixznet committed Sep 23, 2018
1 parent d2f9b6f commit 671c41156a3d4abe252c67aae26095a4946990ee
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/core/Rational.pm6
@@ -24,11 +24,12 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
method new(NuT \nu = 0, DeT \de = 1) {
nqp::unless(
de,
nqp::p6bindattrinvres( # zero-denominator-rational; bind-as-is
nqp::p6bindattrinvres( # zero-denominator-rational; normalize
nqp::p6bindattrinvres(
nqp::create(self),
::?CLASS, '$!denominator', nqp::decont(de)),
::?CLASS, '$!numerator', nqp::decont(nu)),
::?CLASS, '$!numerator', nqp::box_i(
nqp::isgt_I(nu, 0) ?? 1 !! nu ?? -1 !! 0, nu.WHAT)),
nqp::stmts( # normal rational
(my $gcd := nqp::gcd_I(nqp::decont(nu), nqp::decont(de), Int)),
(my $nu := nqp::div_I(nqp::decont(nu), $gcd, NuT)),

0 comments on commit 671c411

Please sign in to comment.
You can’t perform that action at this time.