Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Created February 26, 2017 15:40

Revisions

  1. MasterDuke17 created this gist Feb 26, 2017.
    26 changes: 26 additions & 0 deletions div.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    diff --git a/src/core/Int.pm b/src/core/Int.pm
    index 34e04ea54..6f0907bdd 100644
    --- a/src/core/Int.pm
    +++ b/src/core/Int.pm
    @@ -263,9 +263,18 @@ multi sub infix:<*>(int $a, int $b) returns int {
    }

    multi sub infix:<div>(Int:D \a, Int:D \b) {
    - b
    - ?? nqp::div_I(nqp::decont(a), nqp::decont(b), Int)
    - !! Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a)))
    + nqp::if(
    + b,
    + nqp::if(
    + nqp::isbig_I(nqp::decont(a)) || nqp::isbig_I(nqp::decont(b)),
    + nqp::div_I(nqp::decont(a),nqp::decont(b),Int),
    + nqp::div_i(nqp::decont(a), nqp::decont(b))
    + ),
    + Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a)))
    + )
    +# b
    +# ?? nqp::div_I(nqp::decont(a), nqp::decont(b), Int)
    +# !! Failure.new(X::Numeric::DivideByZero.new(:using<div>, :numerator(a)))
    }
    multi sub infix:<div>(int $a, int $b) returns int {
    # relies on opcode or hardware to detect division by 0