June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,5 @@
|
|||
try {
|
||||
Print("%d\n", 10 / 0);
|
||||
} catch {
|
||||
Print("Divide by zero");
|
||||
}
|
||||
|
|
@ -1,13 +1,6 @@
|
|||
function isdefinite{T<:Number}(n::T)
|
||||
!isequal(n, NaN) && abs(n) != Inf
|
||||
end
|
||||
isdefinite(n::Number) = !isnan(n) && !isinf(n)
|
||||
|
||||
for n in {1, 1//1, 1.0, 1im, 0}
|
||||
d = n/0
|
||||
print("Divding ", n, " by 0 ")
|
||||
if isdefinite(d)
|
||||
println("results in ", d, ".")
|
||||
else
|
||||
println("yields an indefinite value (", d, ").")
|
||||
end
|
||||
for n in (1, 1//1, 1.0, 1im, 0)
|
||||
d = n / 0
|
||||
println("Dividing $n by 0 ", isdefinite(d) ? "results in $d." : "yields an indefinite value ($d).")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
fn test_division(numerator: u32, denominator: u32) {
|
||||
match numerator.checked_div(denominator) {
|
||||
Some(result) => println!("{} / {} = {}", numerator, denominator, result),
|
||||
None => println!("{} / {} results in a division by zero", numerator, denominator)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_division(5, 4);
|
||||
test_division(4, 0);
|
||||
}
|
||||
14
Task/Detect-division-by-zero/VBA/detect-division-by-zero.vba
Normal file
14
Task/Detect-division-by-zero/VBA/detect-division-by-zero.vba
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main()
|
||||
Dim Div
|
||||
If CatchDivideByZero(152, 0, Div) Then Debug.Print Div Else Debug.Print "Error"
|
||||
If CatchDivideByZero(152, 10, Div) Then Debug.Print Div Else Debug.Print "Error"
|
||||
End Sub
|
||||
|
||||
Function CatchDivideByZero(Num, Den, Div) As Boolean
|
||||
On Error Resume Next
|
||||
Div = Num / Den
|
||||
If Err = 0 Then CatchDivideByZero = True
|
||||
On Error GoTo 0
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue