Factorial (FPScript)
Calculates the factorial N! of a natural number.
Syntax
Factorial(N)
The syntax of the Factorial function consists of the following parts:
Part |
Description |
---|---|
N |
The natural number for which the factorial is to be calculated. All data structures are allowed. All numeric data types are permitted. |
Remarks
The data type of the result is always 64-bit floating point.
The structure of the result corresponds to that of the argument N. The calculation is done element-by-element where appropriate.
The result has the unit 1, if N has a unit. Otherwise, it has no unit.
The factorial of a natural number N is the product of the natural numbers from 1 up to N:
N! = 1·2·...·(N-1)·N
It applies per definition 0! = 1.
Floating point values are rounded down to the next integer. For aggregate data structures, only the Y component is considered and the X or, if applicable, Z component is copied into the result without modification.
The factorial is not defined for negative numbers. The function then returns a void value. The function can only calculate factorials to N <= 170, since larger N values lead to an overflow. In such cases, a void value is also returned. The result is only exact up to N <= 21, since the 64-bit floating point data type has an accuracy of 15 decimal places.
If the argument is a list, then the function is executed for each element of the list and the result is also a list.
For complex data types the absolute value is formed.
Available in
FlexPro Basic, Professional, Developer Suite
Examples
Factorial(0) |
Results in 1. |
Factorial(10) |
Results in 3628800. |
Factorial(10.9) |
Results in 3628800. |
Factorial(-3) |
Results in ?. |
Factorial(171) |
Results in ?, since an overflow has occurred. |
Factorial(150) |
Results in 5.71338395644586e+262. The result is accurate to 15 places. |