Skip to content

Commit

Permalink
Merge pull request #1563 from MasterDuke17/whitespace_fixes_for_Ratio…
Browse files Browse the repository at this point in the history
…nal.pm

Whitespace fixes for Rational.pm
  • Loading branch information
pmurias committed Feb 25, 2018
2 parents 235d3f1 + 36caa18 commit 2a8b17a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/Rational.pm
Expand Up @@ -47,6 +47,7 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
}

method nude() { self.REDUCE-ME; $!numerator, $!denominator }

method Num() {
nqp::p6box_n(nqp::div_In(
nqp::decont($!numerator),
Expand All @@ -72,9 +73,13 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
!! fail X::Numeric::DivideByZero.new:
:details('when coercing Rational to Int')
}

multi method Bool(::?CLASS:D:) { nqp::p6bool($!numerator) }

method Bridge() { self.Num }

method Range(::?CLASS:U:) { Range.new(-Inf, Inf) }

method isNaN (--> Bool:D) {
nqp::p6bool(nqp::isfalse($!denominator) && nqp::isfalse($!numerator))
}
Expand Down Expand Up @@ -199,9 +204,9 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
$nu *= $base;
push @quotients, $nu div $de;
}
@quotients.=map(*.base($base));
@quotients .= map(*.base($base));
my @cycle = $nu
?? splice(@quotients, @remainders.first($nu,:k) + 1)
?? splice @quotients, @remainders.first($nu,:k) + 1
!! ();
splice @quotients, 1, 0, '.';
'-' x (self < 0) ~ @quotients.join, @cycle.join;
Expand All @@ -228,8 +233,8 @@ my role Rational[::NuT = Int, ::DeT = ::("NuT")] does Real {
if $!denominator > 1 {
my $gcd = $!denominator gcd $!numerator;
if $gcd > 1 {
nqp::bindattr(self, self.WHAT, '$!numerator', $!numerator div $gcd);
nqp::bindattr(self, self.WHAT, '$!denominator', $!denominator div $gcd);
nqp::bindattr(self,self.WHAT,'$!numerator', $!numerator div $gcd);
nqp::bindattr(self,self.WHAT,'$!denominator',$!denominator div $gcd);
}
}
}
Expand Down

0 comments on commit 2a8b17a

Please sign in to comment.