Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,32 +0,0 @@
|
|||
-- Divide By Zero Detection
|
||||
|
||||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
|
||||
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
|
||||
|
||||
procedure Divide_By_Zero is
|
||||
Fnum : Float := 1.0;
|
||||
Fdenom : Float := 0.0;
|
||||
Fresult : Float;
|
||||
Inum : Integer := 1;
|
||||
Idenom : Integer := 0;
|
||||
Iresult : Integer;
|
||||
begin
|
||||
begin
|
||||
Put("Integer divide by zero: ");
|
||||
Iresult := Inum / Idenom;
|
||||
Put(Item => Iresult);
|
||||
exception
|
||||
when Constraint_Error =>
|
||||
Put("Division by zero detected.");
|
||||
end;
|
||||
New_Line;
|
||||
Put("Floating point divide by zero: ");
|
||||
Fresult := Fnum / Fdenom;
|
||||
if Fresult > Float'Last or Fresult < Float'First then
|
||||
Put("Division by zero detected (infinite value).");
|
||||
else
|
||||
Put(Item => Fresult, Aft => 9, Exp => 0);
|
||||
end if;
|
||||
New_Line;
|
||||
end Divide_By_Zero;
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
try? -> 3/0
|
||||
else -> print "division by zero"
|
||||
a: 0
|
||||
if throws? -> 3 / a
|
||||
-> print "division by zero"
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
DIVIDE foo BY bar GIVING foobar
|
||||
ON SIZE ERROR
|
||||
DISPLAY "Division by zero detected!"
|
||||
END-DIVIDE
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
func checkDivZero a b .
|
||||
func divZero a b .
|
||||
r = a / b
|
||||
if r = number "nan" or r = number "inf" or r = number "-inf"
|
||||
return 1
|
||||
.
|
||||
if r <> r or abs r = 1 / 0 : return 1
|
||||
return 0
|
||||
.
|
||||
print checkDivZero 5 7
|
||||
print checkDivZero -1 0
|
||||
print divZero 5 7
|
||||
print divZero -2 0
|
||||
print divZero 3 0
|
||||
print divZero 0 0
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
(condition-case nil
|
||||
(/ 1 0)
|
||||
(arith-error
|
||||
(message "Divide by zero (either integer or float)")))
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
-->
|
||||
<span style="color: #008080;">try</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">i</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1<span style="color: #0000FF;">/<span style="color: #000000;">0</span>
|
||||
<span style="color: #008080;">catch</span> <span style="color: #000000;">e</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #000000;">e<span style="color: #0000FF;">[<span style="color: #000000;">E_USER<span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">try</span>
|
||||
<span style="color: #7060A8;">puts<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"still running...\n"<span style="color: #0000FF;">)
|
||||
<!--
|
||||
with javascript_semantics -- (not really)
|
||||
try
|
||||
atom d = 0,
|
||||
i = 1/d
|
||||
if platform()=JS then -- (optional/fudge)
|
||||
if d=0 then ?i throw("div by 0") end if
|
||||
end if
|
||||
catch e
|
||||
?e[E_USER]
|
||||
end try
|
||||
puts(1,"still running...\n")
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
function div ($a, $b) {
|
||||
try{$a/$b}
|
||||
catch{"Bad parameters: `$a = $a and `$b = $b"}
|
||||
}
|
||||
div 10 2
|
||||
div 1 0
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
REBOL [
|
||||
Title: "Detect Divide by Zero"
|
||||
URL: http://rosettacode.org/wiki/Divide_by_Zero_Detection
|
||||
]
|
||||
|
||||
; The 'try' word returns an error object if the operation fails for
|
||||
; whatever reason. The 'error?' word detects an error object and
|
||||
; 'disarm' keeps it from triggering so I can analyze it to print the
|
||||
; appropriate message. Otherwise, any reference to the error object
|
||||
; will stop the program.
|
||||
|
||||
div-check: func [
|
||||
"Attempt to divide two numbers, report result or errors as needed."
|
||||
x y
|
||||
/local result
|
||||
] [
|
||||
either error? result: try [x / y][
|
||||
result: disarm result
|
||||
print ["Caught" result/type "error:" result/id]
|
||||
] [
|
||||
print [x "/" y "=" result]
|
||||
]
|
||||
]
|
||||
|
||||
div-check 12 2 ; An ordinary calculation.
|
||||
div-check 6 0 ; This will detect divide by zero.
|
||||
div-check "7" 0.0001 ; Other errors can be caught as well.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
-- 19 May 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'DETECT DIVISION BY ZERO'
|
||||
say version
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
signal on halt name Abend
|
||||
signal on notready name Abend
|
||||
signal on novalue name Abend
|
||||
signal on syntax name Abend
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
Function div(num,den)
|
||||
On Error Resume Next
|
||||
n = num/den
|
||||
If Err.Number <> 0 Then
|
||||
div = Err.Description & " is not allowed."
|
||||
Else
|
||||
div = n
|
||||
End If
|
||||
End Function
|
||||
|
||||
WScript.StdOut.WriteLine div(6,3)
|
||||
WScript.StdOut.WriteLine div(6,0)
|
||||
WScript.StdOut.WriteLine div(7,-4)
|
||||
Loading…
Add table
Add a link
Reference in a new issue