Oihana PHP

factorial.php

Table of Contents

Functions

factorial()  : int
Computes the factorial `n!` of a non-negative integer.

Functions

factorial()

Computes the factorial `n!` of a non-negative integer.

factorial(int $n) : int

factorial(0) is 1. The argument is capped at 20 because 21! exceeds PHP_INT_MAX and could no longer be represented exactly as an int.

Parameters
$n : int

A non-negative integer in the range [0, 20].

Tags
throws
InvalidArgumentException

If $n is negative or greater than 20.

example
use function oihana\core\maths\factorial;

echo factorial( 0 ) ; // 1
echo factorial( 5 ) ; // 120
echo factorial( 10 ) ; // 3628800
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
int

The factorial of $n.

On this page

Search results