The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
factorial.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file factorial.c
5 
6  \version V1.1
7  \date 07.07.14
8  \brief
9 
10  \copyright (c) Dr. Andrew C. R. Martin, UCL, 1996-2014
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.0 10.09.96 Original
50 - V1.1 07.07.14 Use bl prefix for functions By: CTP
51 
52 *************************************************************************/
53 /* Doxygen
54  -------
55  #GROUP Maths
56  #SUBGROUP Miscellaneous
57  #FUNCTION blFactorial()
58  Calculates the factorial of an integer.
59 */
60 /************************************************************************/
61 /* Includes
62 */
63 #include "SysDefs.h"
64 
65 /************************************************************************/
66 /* Defines and macros
67 */
68 
69 /************************************************************************/
70 /* Globals
71 */
72 
73 /************************************************************************/
74 /* Prototypes
75 */
76 
77 
78 /************************************************************************/
79 /*>ULONG blFactorial(int n)
80  ------------------------
81 *//**
82 
83  Calculates the factorial of an integer.
84  Returns 0 on numeric overflow.
85 
86 - 09.09.96 Original By: ACRM
87 - 07.07.14 Use bl prefix for functions By: CTP
88 */
90 {
91  int i;
92  ULONG ret = 1L,
93  prev = 0L;
94 
95  for(i=2; i<=n; i++)
96  {
97  ret *= (ULONG)i;
98  if(ret < prev)
99  return(0);
100  prev = ret;
101  }
102 
103  return(ret);
104 }
105 
106 
unsigned long ULONG
Definition: SysDefs.h:66
System-type variable type definitions.
ULONG blFactorial(int n)
Definition: factorial.c:89