Factorial – The factorial of a number

Factorial – The factorial of a number

' The factorial of a number'' if NUMBER is negative or >170 it raises an' "subscript out of range" errorFunction Factorial(ByVal number As Long) As Double    Static result(170) As Double        ' this routine is very fast because it    ' caches all the possible results    If result(0) = 0 Then        ' this is the first time it is executed        Dim i As Long        result(0) = 1        ' Factorial(170) is the highest factorial        ' value that can be stored in a Double        For i = 1 To 170            result(i) = result(i - 1) * i        Next    End If        ' just read the result from the cached array    Factorial = result(number)        End Function' *** UPDATE ***' Rick Rothstein (MVP-VB) sent us the following update for the Factorial ' function. It reports whole number results up to an argument value of 27 (a 29-' digit answer containing 23 significant digits) before switching to power-of-' ten notation.' The factorial of a number'' if NUMBER is negative or >170 it raises an' "subscript out of range" errorFunction Factorial(ByVal N As Integer) As Variant    Static Result(170) As Variant    Dim X As Integer    ' this routine is very fast because it    ' caches all the possible results    If Result(0) = 0 Then        ' convert to Decimal data type        Result(0) = CDec(1)        ' Factorial(170) is the highest factorial        ' value that can be stored in a Double        For X = 1 To 170            ' for X<28, calculate using Decimal data            ' type; use Double data type afterwards            If X = 28 Then                Result(28) = 28 * CDbl(Result(27))            Else                Result(X) = X * Result(X - 1)            End If        Next    End If    ' just read the result from the cached array    Factorial = Result(N)End Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of