Home > Software engineering >  Simple floating point arithmetic in VBA throwing error
Simple floating point arithmetic in VBA throwing error

Time:10-26

I have the following code in an Excel VBA module:

Function f(a, b, c, d)
f = 1.95 * a * (b / c) ^ 0.06 * (d / c) ^ 0.06
End Function

Sub callf()
Debug.Print (f(-7, 10, 3.5, -6))
End Sub

When I run the sub callf I get an error:

Run time error '5': Invalid procedure call or argument

I am at a loss as to why this occurs. Am I not doing simple floating point operations here? Any ideas?

CodePudding user response:

Because you are raising -1.7 to the power 0.06. The result is a complex number.

  • Related