Matematické funkce V - Faktoriál a logaritmus

Funkce:

' Pokud je číslo záporné nebo >170, vygeneruje chybu
' "subscript out of range"

Function Factorial(ByVal number As Long) As Double

    Static result(170) As Double
    
    If result(0) = 0 Then
        Dim i As Long
        result(0) = 1
        ' Factorial(170) je nejvyšší hodnota faktoriálu,
        ' která jde  uložit do Double
        For i = 1 To 170
            result(i) = result(i - 1) * i
        Next
    End If
    
    Factorial = result(number)
        
End Function

Function Log10(number As Double) As Double 

   Log10 = Log(number) / 2.30258509299405 

End Function

Zpět

Autor: The Bozena