How to resolve the algorithm Detect division by zero step by step in the langur programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Detect division by zero step by step in the langur programming language
Table of Contents
Problem Statement
Write a function to detect a divide by zero error without checking if the denominator is zero.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Detect division by zero step by step in the langur programming language
Source code in the langur programming language
val .div = f(.x, .y) {
[.x / .y, true]
catch {
if matching(re/division by 0/, _err["msg"]) {
[0, false]
} else {
# rethrow the error if not division by 0
throw
}
}
}
writeln .div(3, 2)
writeln .div(3, 0)
You may also check:How to resolve the algorithm Execute SNUSP step by step in the Haskell programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the APL programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Component Pascal programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Polynomial long division step by step in the Perl programming language