Plugins
Loading...
Searching...
No Matches
factorial.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
3 * SPDX-License-Identifier: EUPL-1.2
4 * SPDX-FileContributor: Sabine Stichel
5 * SPDX-FileContributor: Goethe Universität Frankfurt
6 * SPDX-FileType: SOURCE
7 *
8 * This file is part of d3f++.
9 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
10 */
11
12/*
13 * Original by J.Musuuza
14 */
15
16// extern headers
17#include <iostream>
18#include <sstream>
19#include <fstream>
20#include <string>
21#include <cmath>
22#include <vector>
23
24
25#define _USE_MATH_DEFINES
26#include <math.h>
27#include <float.h> //for DBL_MAX
28#include <iomanip>
29#include <cstdlib>
30#include <time.h>
31#include "common/common.h"
32
36#include "bridge/bridge.h"
37#include "lib_disc/domain.h"
47#include "common/parser/rapidxml/rapidxml_print.hpp"
48#include "common/parser/rapidxml/rapidxml.hpp"
49#include "../plugins/experimental/biogas/save_load.h"
50
51
52//using namespace std;
53//using namespace rapidxml;
54#ifdef UG_FOR_LUA
56#endif
57
58namespace ug{
59namespace d3f{
60
61
62/*functions copied from: factorial.c*/
63
65// double Factorial( int n ) //
66// //
67// Description: //
68// This function computes n! for 0 <= n <= Factorial_Max_Arg(). If //
69// n > Factorial_Max_Arg(), then DBL_MAX is returned and if n < 0, then //
70// 0 is returned. //
71// //
72// Arguments: //
73// int n Argument of the Factorial function. //
74// //
75// Return Values: //
76// If n is negative, then 0 is returned. If n > Factorial_Max_Arg(), //
77// then DBL_MAX is returned. If 0 <= n <= Factorial_Max_Arg(), then //
78// n! is returned. //
79// //
80// Example: //
81// int n; //
82// double x; //
83// //
84// x = Factorial( n ); //
86template <typename TData, int dim, typename TRet>
88{
89 // For a negative argument (n < 0) return 0.0 //
90 if ( n < 0 )
91 return 0.0;
92 // For a large postive argument (n >= N) return DBL_MAX //
93 if ( n >= N )
94 return DBL_MAX;
95 // Otherwise return n!. //
96 return (double) factorials[n];
97}
98
99
101// long double xFactorial( int n ) //
102// //
103// Description: //
104// This function computes n! for 0 <= n <= Factorial_Max_Arg(). If //
105// n > Factorial_Max_Arg(), then DBL_MAX is returned and if n < 0, then //
106// 0 is returned. //
107// //
108// Arguments: //
109// int n Argument of the Factorial function. //
110// //
111// Return Values: //
112// If n is negative, then 0 is returned. If n > Factorial_Max_Arg(), //
113// then DBL_MAX is returned. If 0 <= n <= Factorial_Max_Arg(), then //
114// n! is returned. //
115// //
116// Example: //
117// int n; //
118// long double x; //
119// //
120// x = xFactorial( n ); //
122template <typename TData, int dim, typename TRet>
124{
125 // For a negative argument (n < 0) return 0.0 //
126 if ( n < 0 )
127 return 0.0L;
128 // For a large postive argument (n >= N) return DBL_MAX //
129 if ( n >= N )
130 return (long double) DBL_MAX;
131 // Otherwise return n!. //
132 return factorials[n];
133}
134
135
137// int Factorial_Max_Arg( void ) //
138// //
139// Description: //
140// This function returns the maximum argument of the Factorial function //
141// for which a number < DBL_MAX is returned. //
142// //
143// Arguments: //
144// none //
145// //
146// Return Values: //
147// N-1 //
148// //
149// Example: //
150// int x; //
151// //
152// x = Factorial_Max_Arg(); //
154
155template <typename TData, int dim, typename TRet>
157{
158 return N - 1;
159}
160
161
162}
163}
int Factorial_Max_Arg()
Definition factorial.h:156
double Factorial(int n)
Definition factorial.h:87
long double xFactorial(int n)
Definition factorial.h:123