NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
factorial.hpp
Go to the documentation of this file.
1
28#pragma once
29
31#include "NumCpp/Core/Types.hpp"
32#include "NumCpp/NdArray.hpp"
33
34#ifndef NUMCPP_NO_USE_BOOST
35#include "boost/math/special_functions/factorials.hpp"
36#endif
37
38#include <limits>
39
40namespace nc::special
41{
42 //============================================================================
43 // Method Description:
49 inline double factorial(uint32 inValue)
50 {
51#ifndef NUMCPP_NO_USE_BOOST
52 if (inValue <= boost::math::max_factorial<double>::value)
53 {
54 return boost::math::factorial<double>(inValue);
55 }
56
57 return std::numeric_limits<double>::infinity();
58#else
59 double result = 1.;
60 for (uint32 i = 2; i <= inValue; ++i)
61 {
62 result *= static_cast<double>(i);
63 }
64
65 return result;
66#endif
67 }
68
69 //============================================================================
70 // Method Description:
77 {
79
81 inArray.cend(),
82 returnArray.begin(),
83 [](uint32 inValue) -> double { return factorial(inValue); });
84
85 return returnArray;
86 }
87} // namespace nc::special
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
Definition airy_ai.hpp:39
double factorial(uint32 inValue)
Definition factorial.hpp:49
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
std::uint32_t uint32
Definition Types.hpp:40