indeterminate 0/0

  • Thread starter Thread starter integreat
  • Start date Start date
I

integreat

Is there a way to force VBA to do a division by zero without giving th
"divide by zero" error. I need a way to overrride this error but need
0/0 to equal
 
You can check the numerator and denominator to see if either/both are equal to
0.

=IF(B1<>0,A1/B1,IF(A1=0,1,"divided by 0, but not 0/0"))

0/0 will return 1

nonzero/0 will return "divided by 0, but not 0/0". Change that to what you
want.
 
Perhaps

Function DivideBy(denom, div)

If denom = 0 And div = 0 Then
DivideBy = 1
Else
DivideBy = denom / div
End If

End Function

MsgBox DivideBy(0,0)

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
Just in case you really do want Visual Basic:

Function mydivider(a, b)
If b <> 0 Then
temp = a / b
ElseIf a = 0 Then
temp = 1
End If
mydivider = temp
End Function


best wishes
 
"divide by zero" error. I need a way to override this error but need
0/0 to equal 1

Hi. Just for discussion, 0/0 is an "Overflow" error.

Sub Demo()
Dim Ans
On Error Resume Next

'// 6 Overflow
Ans = 0 / 0
Debug.Print Err.Number; Err.Description

'// 11 Division by zero
Ans = 2 / 0
Debug.Print Err.Number; Err.Description

'// Maybe...
If Err.Number = 6 Then Ans = 1
Err.Clear
On Error GoTo 0
End Sub

(But you are correct, certain math programs treat 0/0 as Indeterminate vs
Excel's Overflow)
 
And that indeterminate makes sense, too.

numerator/demoninator = Quotient

which means that
numerator = Quotient * denominator

If the denominator is 0 and the numerator is non-zero, there are no non-zero
numerators that could make:
numerator = quotient * 0
correct.

If both the denominator and numerator = 0, then there are way too many correct
answers that make this:

0 = quotient * 0
(0 * any number = 0, so all numbers are correct)
 
Hi. Other arguments for "indeterminate" are with limits. If you take the
limit of x/x as x approaches 0, then the answer is 1.(2x/x is 2..etc)
The correct answer to what you want with 0/0 depends on what you are doing.
Hence...indeterminate. Interesting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top