The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
factdiv.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file factdiv.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 blFactdiv()
58  Calculates the factorial of one number divided by the factorial of
59  another (smaller) number.
60 */
61 /************************************************************************/
62 /* Includes
63 */
64 #include "SysDefs.h"
65 
66 /************************************************************************/
67 /* Defines and macros
68 */
69 
70 /************************************************************************/
71 /* Globals
72 */
73 
74 /************************************************************************/
75 /* Prototypes
76 */
77 
78 
79 /************************************************************************/
80 /*>ULONG blFactdiv(int n1, int n2)
81  -------------------------------
82 *//**
83 
84  Calculates the factorial of one number divided by the factorial of
85  another (smaller) number.
86  Returns 0 on numeric overflow or if n2 > n1
87 
88 - 09.09.96 Original By: ACRM
89 - 07.07.14 Use bl prefix for functions By: CTP
90 */
91 ULONG blFactdiv(int n1, int n2)
92 {
93  int i;
94  ULONG ret = 1L,
95  prev = 0L;
96 
97  if(n2 > n1)
98  return(0);
99 
100  for(i=n2+1; i<=n1; i++)
101  {
102  ret *= (ULONG)i;
103  if(ret < prev)
104  return(0);
105  prev = ret;
106  }
107 
108  return(ret);
109 }
110 
111 
unsigned long ULONG
Definition: SysDefs.h:66
ULONG blFactdiv(int n1, int n2)
Definition: factdiv.c:91
System-type variable type definitions.