September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,28 @@
begin
% integer division procedure %
% sets c to a divided by b, returns true if the division was OK, %
% false if there was division by zero %
logical procedure divideI ( integer value a, b; integer result c ) ;
begin
% set exception handling to allow integer division by zero to occur once %
INTDIVZERO := EXCEPTION( false, 1, 0, false, "INTDIVZERO" );
c := a div b;
not XCPNOTED(INTDIVZERO)
end divideI ;
% real division procedure %
% sets c to a divided by b, returns true if the division was OK, %
% false if there was division by zero %
logical procedure divideR ( long real value a, b; long real result c ) ;
begin
% set exception handling to allow realdivision by zero to occur once %
DIVZERO := EXCEPTION( false, 1, 0, false, "DIVZERO" );
c := a / b;
not XCPNOTED(DIVZERO)
end divideR ;
integer c;
real d;
write( divideI( 4, 2, c ) ); % prints false as no exception %
write( divideI( 5, 0, c ) ); % prints true as division by zero was detected %
write( divideR( 4, 2, d ) ); % prints false as no exception %
write( divideR( 5, 0, d ) ) % prints true as division by zero was detected %
end.

View file

@ -23,7 +23,7 @@ begin
New_Line;
Put("Floating point divide by zero: ");
Fresult := Fnum / Fdenom;
if Fresult > Float'Last then
if Fresult > Float'Last or Fresult < Float'First then
Put("Division by zero detected (infinite value).");
else
Put(Item => Fresult, Aft => 9, Exp => 0);

View file

@ -1,10 +0,0 @@
100 REM TRY
110 ONERR GOTO 200
120 D = - 44 / 0
190 END
200 REM CATCH
210 E = PEEK (222) < > 133
220 POKE 216,0: REM ONERR OFF
230 IF E THEN RESUME
240 CALL - 3288: REM RECOVER
250 PRINT "DIVISION BY ZERO"

View file

@ -1,19 +0,0 @@
PROCdivide(-44, 0)
PROCdivide(-44, 5)
PROCdivide(0, 5)
PROCdivide(5, 0)
END
DEF PROCdivide(numerator, denominator)
ON ERROR LOCAL IF FALSE THEN
REM 'Try' clause:
PRINT numerator / denominator
ELSE
REM 'Catch' clause:
CASE ERR OF
WHEN 18: PRINT "Division by zero"
WHEN 20: PRINT "Number too big"
OTHERWISE RESTORE LOCAL : ERROR ERR, REPORT$
ENDCASE
ENDIF
ENDPROC

View file

@ -0,0 +1,6 @@
Public Sub Main()
Try Print 1 / 0
If Error Then Print Error.Text
End

View file

@ -0,0 +1,20 @@
// version 1.1
fun divideByZero(x: Int, y:Int): Boolean =
try {
x / y
false
} catch(e: ArithmeticException) {
true
}
fun main(args: Array<String>) {
val x = 1
val y = 0
if (divideByZero(x, y)) {
println("Attempted to divide by zero")
} else {
@Suppress("DIVISION_BY_ZERO")
println("$x / $y = ${x / y}")
}
}

View file

@ -1,12 +0,0 @@
result = DetectDividebyZero(1, 0)
Function DetectDividebyZero(a, b)
On Error GoTo [Error]
DetectDividebyZero= (a/ b)
Exit Function
[Error]
If Err = 11 Then '11 is the error number raised when divide by zero occurs
Notice "Divide by Zero Detected!"
End If
End Function

View file

@ -1,6 +0,0 @@
10 ON ERROR GOTO 60
20 PRINT 2/3
30 PRINT 3/5
40 PRINT 4/0
50 END
60 IF ERR=11 THEN PRINT "Division by zero in line"ERL:RESUME 50

View file

@ -0,0 +1,7 @@
var %n = $rand(0,1)
if ($calc(1/ %n) == $calc((1/ %n)+1)) {
echo -ag Divides By Zero
}
else {
echo -ag Does Not Divide By Zero
}

View file

@ -0,0 +1,18 @@
/* REXX **************************************************************
* program demonstrates detects and handles division by zero.
* translated from REXX:
* removed fancy error reporting (ooRexx does not support linesize)
* removed label Novalue (as novalue is not enabled there)
* 28.04.2013 Walter Pachl
*********************************************************************/
Signal on Syntax /*handle all REXX syntax errors. */
x = sourceline() /*being cute, x=size of this pgm.*/
y = x-x /*setting to zero the obtuse way.*/
z = x/y /* attempt to divide by 0 */
exit /* will not be reached */
Syntax:
Say 'Syntax raised in line' sigl
Say sourceline(sigl)
Say 'rc='rc '('errortext(rc)')'
Exit 12

View file

@ -0,0 +1,6 @@
try
integer i = 1/0
catch e
?e[E_USER]
end try
puts(1,"still running...\n")

View file

@ -1,13 +0,0 @@
;Set up a Procedure to handle any Error
Procedure MyErrorHandler()
Define txt$="The following error happened."+#CRLF$+ ErrorMessage()+"at line "+Str(ErrorLine())
MessageRequester("OnError test", txt$)
EndProcedure
; Tell where to go if an Error happens
OnErrorCall(@MyErrorHandler())
;Now, do something very stupid so that we may see an Error...
Repeat
A=Random(100)/Random(100)
ForEver

View file

@ -1,2 +0,0 @@
Define.d a, b
Debug a/b

View file

@ -1,7 +0,0 @@
on error goto [error]
a = 1 / 0
wait
[error] ' error 11 is division by zero err number
If err = 11 Then print "Division by Zero"
wait

View file

@ -0,0 +1,7 @@
func div_check(a, b){
var result = a/b
result.abs == Inf ? nil : result
}
 
say div_check(10, 2) # 5
say div_check(1, 0) # nil (detected)

View file

@ -0,0 +1,6 @@
func div_check(a, b){
Perl.eval("#{a} / #{b}")
}
 
say div_check(10, 2) # 5
say div_check(1, 0) # nil (detected)

View file

@ -1,13 +0,0 @@
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)

View file

@ -0,0 +1 @@
fcn f(x,y){try{x/y}catch(MathError){println(__exception)}}