Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
1 0 n:/ Inf? . cr
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
shared void run() {
|
||||
|
||||
//integers divided by zero throw an exception
|
||||
try {
|
||||
value a = 1 / 0;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//floats divided by zero produce infinity
|
||||
print(1.0 / 0 == infinity then "division by zero!" else "not division by zero!");
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DBZ(REAL8 Dividend,INTEGER8 Divisor) := Quotient/Divisor;
|
||||
|
||||
#option ('divideByZero', 'zero');
|
||||
DBZ(10,0); //returns 0.0
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
DBZ(REAL8 Dividend,INTEGER8 Divisor) := Quotient/Divisor;
|
||||
#option ('divideByZero', 'fail');
|
||||
DBZ(10,0); //returns error message "Error: System error: -1: Division by zero (0, 0), -1,"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
DBZ(REAL8 Dividend,INTEGER8 Divisor) := Quotient/Divisor;
|
||||
#option ('divideByZero', 'nan');
|
||||
DBZ(10,0); //returns 'nan'
|
||||
|
||||
/* NOTE: This is only currently supported for real numbers. Division by zero creates a quiet NaN,
|
||||
which will propogate through any real expressions it is used in.
|
||||
You can use NOT ISVALID(x) to test if the value is a NaN.
|
||||
Integer and decimal division by zero continue to return 0.
|
||||
*/
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
PROGRAM DIV_BY_ZERO
|
||||
|
||||
EXCEPTION
|
||||
IF ERR=11 THEN PRINT("Division by Zero") END IF
|
||||
END EXCEPTION
|
||||
|
||||
BEGIN
|
||||
PRINT(0/3)
|
||||
PRINT(3/0)
|
||||
END PROGRAM
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Const divByZeroResult As Integer = -9223372036854775808
|
||||
|
||||
Sub CheckForDivByZero(result As Integer)
|
||||
If result = divByZeroResult Then
|
||||
Print "Division by Zero"
|
||||
Else
|
||||
Print "Division by Non-Zero"
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Dim As Integer x, y
|
||||
|
||||
x = 0 : y = 0
|
||||
CheckForDivByZero(x/y) ' automatic conversion to type of parameter which is Integer
|
||||
x = 1
|
||||
CheckForDivByZero(x/y)
|
||||
x = -1
|
||||
CheckForDivByZero(x/y)
|
||||
y = 1
|
||||
CheckForDivByZero(x/y)
|
||||
Print
|
||||
Print "Press any key to exit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
on error stop
|
||||
dim as long a
|
||||
print a / 0
|
||||
14
Task/Detect-division-by-zero/I/detect-division-by-zero.i
Normal file
14
Task/Detect-division-by-zero/I/detect-division-by-zero.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function isdivbyzero(a, b) {
|
||||
var c = a/b
|
||||
if (c = 0) and (a != 0) or (a = 0) and (c >= 0)
|
||||
print( a, "/", b, " is a division by zero.")
|
||||
return
|
||||
end
|
||||
print( a, "/", b, " is not division by zero.")
|
||||
}
|
||||
|
||||
software {
|
||||
isdivbyzero(5, 0)
|
||||
isdivbyzero(5, 2)
|
||||
isdivbyzero(0, 0)
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
define dividehandler(a,b) => {
|
||||
(
|
||||
#a->isNotA(::integer) && #a->isNotA(::decimal) ||
|
||||
#b->isNotA(::integer) && #b->isNotA(::decimal)
|
||||
) ? return 'Error: Please supply all params as integers or decimals'
|
||||
protect => {
|
||||
handle_error => { return 'Error: Divide by zero' }
|
||||
local(x = #a / #b)
|
||||
return #x
|
||||
}
|
||||
}
|
||||
|
||||
dividehandler(1,0)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
on div (a, b)
|
||||
-- for simplicity type check of vars omitted
|
||||
res = value("float(a)/b")
|
||||
if voidP(res) then
|
||||
_player.alert("Division by zero!")
|
||||
else
|
||||
return res
|
||||
end if
|
||||
end
|
||||
12
Task/Detect-division-by-zero/Nim/detect-division-by-zero.nim
Normal file
12
Task/Detect-division-by-zero/Nim/detect-division-by-zero.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# In debug builds division by zero exceptions are thrown by default, in release
|
||||
# builds not. We can still enable them explicitly.
|
||||
{.push overflowChecks: on.}
|
||||
proc divCheck(x, y): bool =
|
||||
try:
|
||||
discard x div y
|
||||
except DivByZeroError:
|
||||
return true
|
||||
return false
|
||||
{.pop.} # Restore default check settings
|
||||
|
||||
echo divCheck(2, 0)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
: divideCheck(n)
|
||||
| e |
|
||||
try: e [ 128 n / ] when: [ "Zero detected..." . ]
|
||||
"Leaving" println ;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
dcl-c DIVIDE_BY_ZERO 00102;
|
||||
|
||||
dcl-s result zoned(5:2);
|
||||
dcl-s value1 zoned(5:2);
|
||||
dcl-s value2 zoned(5:2);
|
||||
|
||||
value1 = 10;
|
||||
value2 = 0;
|
||||
|
||||
monitor;
|
||||
eval(h) result = value1 / value2; // Using half rounding here for the eval result
|
||||
on-error DIVIDE_BY_ZERO;
|
||||
// Initialise the result to 0. Consider other messaging perhaps.
|
||||
result = 0;
|
||||
endmon;
|
||||
|
||||
*inlr = *on;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Try
|
||||
see 9/0
|
||||
Catch
|
||||
see "Catch!" + nl + cCatchError
|
||||
Done
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
func div(a, b){
|
||||
try {
|
||||
a / b
|
||||
}
|
||||
catch { |_, msg|
|
||||
say "tried to divide by zero" if (msg ~~ /Division by zero/)
|
||||
nil
|
||||
}
|
||||
}
|
||||
|
||||
say div(10, 2); # 5
|
||||
say div(1, 0); # inf, 1/0 constants are substituted for infinity
|
||||
say div(1.c, 0.c); # nil, and prints "tried to divide by zero" (complex numbers)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def div_check (int x, int y)
|
||||
try
|
||||
/ x y
|
||||
return false
|
||||
catch divzeroerror
|
||||
return true
|
||||
end try
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
def div(x;y): if y==0 then error("NaN") else x/y end;
|
||||
|
|
@ -0,0 +1 @@
|
|||
try div(3;0) catch if "NaN" then "div by 0 error detected" else . end
|
||||
Loading…
Add table
Add a link
Reference in a new issue