]> git.donarmstrong.com Git - mothur.git/blob - common.h
working on pam
[mothur.git] / common.h
1 /*
2  * common.h
3  *
4  * $Id$
5  *
6  *****************************************************************************
7  *
8  * Copyright (c) 2004,  Luke Sheneman
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without 
12  * modification, are permitted provided that the following conditions 
13  * are met:
14  * 
15  *  + Redistributions of source code must retain the above copyright 
16  *    notice, this list of conditions and the following disclaimer. 
17  *  + Redistributions in binary form must reproduce the above copyright 
18  *    notice, this list of conditions and the following disclaimer in 
19  *    the documentation and/or other materials provided with the 
20  *    distribution. 
21  *  + The names of its contributors may not be used to endorse or promote 
22  *    products derived  from this software without specific prior 
23  *    written permission. 
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
35  * POSSIBILITY OF SUCH DAMAGE.  
36  *
37  *****************************************************************************
38  *
39  * A header file filled with common definitions and simple inline functions
40  *
41  *****************************************************************************
42  *
43  * AUTHOR:
44  * 
45  *   Luke Sheneman
46  *   sheneman@cs.uidaho.edu
47  *
48  */
49
50
51 #ifndef _INC_NJ_COMMON_H_
52 #define _INC_NJ_COMMON_H_ 1
53
54 #include <math.h>
55 #include <float.h>
56
57
58 #define NJ_AMBIGUITY_CHAR    63  /* ? character */
59
60
61 /*
62  * this macro defines the number of cells in the diagonal matrix 
63  * based on the number of taxa involved
64  *
65  */
66 #define NJ_NCELLS(a)       ( ((a)*(a+1))/2 )
67
68
69
70
71 /*
72  * NJ_MAP() - 
73  *
74  * Thus function maps i, j coordinates to the correct offset into 
75  * the distance matrix
76  *
77  */
78 static inline
79 long int 
80 NJ_MAP(long int i,
81        long int j,
82        long int ntaxa) {
83   
84   return((i*(2*ntaxa-i-1))/2 + j);
85 }
86
87
88 static inline
89 int
90 NJ_FLT_EQ(float x,
91           float y) {
92   
93   if(fabs(x - y)<FLT_EPSILON) {
94     return(1);
95   } else {
96     return(0);
97   }
98 }
99
100
101
102 static inline
103 int
104 NJ_FLT_LT(float x,
105           float y) {
106   
107   if(NJ_FLT_EQ(x, y)) {
108     return(0);
109   } else {
110     if(x < y) {
111       return(1);
112     } else {
113       return(0);
114     }
115   }
116 }
117
118
119 static inline
120 int
121 NJ_FLT_GT(float x,
122           float y) {
123   
124   if(NJ_FLT_EQ(x, y)) {
125     return(0);
126   } else {
127     if(x > y) {
128       return(1);
129     } else {
130       return(0);
131     }
132   }
133 }
134
135
136
137
138 #endif /* _INC_NJ_COMMON_H_ */
139
140
141