Sgn Function |
No
Sgn(number)
number
Use: Required
Data Type: Numeric
A numeric expression.
A Variant of subtype Integer.
Determines the sign of a number.
The return value of the Sgn function is determined by the sign of number:
If number is... | Sgn Returns |
---|---|
Positive | 1 |
Zero | 0 |
Negative | –1 |
I suppose that someone, somewhere, has found a really good use for the Sgn function. However, its usefulness escapes me, because you need to carry out a test on the return value of the function identical to that which you could use on the number to find its sign.
If you're planning on using the Sgn function to evaluate a result to False (0) or True (any nonzero value), you could also use the CBool function.
The major use for Sgn—and a fairly trivial one—is to determine the sign of an expression. It's equivalent to the following code:
Public Function Sgn(varNumber as Variant) as Integer If varNumber > 0 Then Sgn = 1 ElseIf varNumber = 0 Then Sgn = 0 Else Sgn = -1 End If
Sgn is useful in cases in which the sign of a quantity defines the sign of an expression. For example:
lngResult = lngQty * Sgn(lngValue)
18.191.212.113