MCPcopy Index your code
hub / github.com/RustPython/RustPython / factorial

Function factorial

crates/stdlib/src/math.rs:801–812  ·  view source on GitHub ↗
(x: PyIntRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

799
800 #[pyfunction]
801 fn factorial(x: PyIntRef, vm: &VirtualMachine) -> PyResult<BigInt> {
802 // Check for negative before overflow - negative values are always invalid
803 if x.as_bigint().is_negative() {
804 return Err(vm.new_value_error("factorial() not defined for negative values"));
805 }
806 let n: i64 = x.try_to_primitive(vm).map_err(|_| {
807 vm.new_overflow_error("factorial() argument should not exceed 9223372036854775807")
808 })?;
809 pymath::math::integer::factorial(n)
810 .map(|r| r.into())
811 .map_err(|_| vm.new_value_error("factorial() not defined for negative values"))
812 }
813
814 #[pyfunction]
815 fn perm(

Callers 1

Calls 4

as_bigintMethod · 0.80
try_to_primitiveMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45

Tested by 1