A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,4 @@
|
|||
USE: math.floats.env
|
||||
|
||||
: try-div ( a b -- )
|
||||
'[ { +fp-zero-divide+ } [ _ _ /f . ] with-fp-traps ] try ;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def divide: x by: y {
|
||||
try {
|
||||
x / y
|
||||
} catch DivisionByZeroError => e {
|
||||
e message println # prints error message
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def dividesByZero = { double n, double d ->
|
||||
assert ! n.infinite : 'Algorithm fails if the numerator is already infinite.'
|
||||
(n/d).infinite || (n/d).naN
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
((3d)..(0d)).each { i ->
|
||||
((2d)..(0d)).each { j ->
|
||||
println "${i}/${j} divides by zero? " + dividesByZero(i,j)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
FUNCTION zero_divide(num, denom)
|
||||
XEQ( num// "/" // denom, *99) ! on error jump to label 99
|
||||
zero_divide = 0 ! division OK
|
||||
RETURN
|
||||
|
||||
99 zero_divide = 1
|
||||
END
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
zero_divide(0, 1) returns 0 (false)
|
||||
zero_divide( 1, 3-2-1 ) returns 1 (true)
|
||||
|
|
@ -0,0 +1 @@
|
|||
if not finite( <i>expression</i> ) then ...
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
procedure main()
|
||||
&error := 1
|
||||
udef := 1 / 0 | stop("Run-time error ", &errornumber, " : ", &errortext," in line #",&line," - converted to failure")
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
funnydiv=: 0 { [: (,:'division by zero detected')"_^:(_ e. |@,) (,>:)@:(,:^:(0<#@$))@[ %"_1 _ ]
|
||||
10
Task/Detect-division-by-zero/J/detect-division-by-zero-2.j
Normal file
10
Task/Detect-division-by-zero/J/detect-division-by-zero-2.j
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
3 funnydiv 2
|
||||
1.5
|
||||
3 funnydiv 0
|
||||
division by zero detected
|
||||
0 funnydiv 0
|
||||
division by zero detected
|
||||
0 funnydiv 3
|
||||
0
|
||||
2 3 4 funnydiv 5
|
||||
0.4 0.6 0.8
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
|
|
@ -0,0 +1 @@
|
|||
ifelse(eval(2/0),`',`detected divide by zero or some other error of some kind')
|
||||
|
|
@ -0,0 +1 @@
|
|||
if not bit.isFinite (<i>expression</i>) then...
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
DIV(A,B) ;Divide A by B, and watch for division by zero
|
||||
;The ANSI error code for division by zero is "M9".
|
||||
;$ECODE errors are surrounded by commas when set.
|
||||
NEW $ETRAP
|
||||
SET $ETRAP="GOTO DIVFIX^ROSETTA"
|
||||
SET D=(A/B)
|
||||
SET $ETRAP=""
|
||||
QUIT D
|
||||
DIVFIX
|
||||
IF $FIND($ECODE,",M9,")>1 WRITE !,"Error: Division by zero" SET $ECODE="" QUIT ""
|
||||
QUIT "" ; Fall through for other errors
|
||||
|
|
@ -0,0 +1 @@
|
|||
Check[2/0, Print["division by 0"], Power::infy]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
f(a, b) := block([q: errcatch(a / b)], if emptyp(q) then 'error else q[1]);
|
||||
|
||||
f(5, 6);
|
||||
5 / 6
|
||||
|
||||
f(5, 0;)
|
||||
'error
|
||||
Loading…
Add table
Add a link
Reference in a new issue