Detect division by zero: Difference between revisions

→‎{{header|Perl 6}}: added multi variant
(Pari/GP)
(→‎{{header|Perl 6}}: added multi variant)
Line 551:
say div(1,0); # Inf, 1/0 constants are substituted for Infinity
say div(1, sin(0)); # undef, and prints "tried to divide by zero"
</lang>
 
===Using Multi Method Dispatch===
 
<lang perl6>multi div($a, $b){ return $a / $b }
multi div($a, $b where { $b == 0 }){
say 'lolicheatsyou';
return 1;
}
 
say div(1, sin(0)); # prints "lolicheatsyou" newline "1"
</lang>
 
Anonymous user