Debian Codegraph @

external/gsl/gsl_vector__minmax_source.c

raw
1 /* vector/minmax_source.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 BASE
21 FUNCTION(gsl_vector,max) (const TYPE(gsl_vector) * v)
22 {
23 /* finds the largest element of a vector */
24
25 const size_t N = v->size ;
26 const size_t stride = v->stride ;
27
28 BASE max = v->data[0 * stride];
29 size_t i;
30
31 for (i = 0; i < N; i++)
32 {
33 BASE x = v->data[i*stride];
34 if (x > max)
35 max = x;
36 #ifdef FP
37 if (isnan (x))
38 return x;
39 #endif
40 }
41
42 return max;
43 }
44
45 BASE
46 FUNCTION(gsl_vector,min) (const TYPE(gsl_vector) * v)
47 {
48 /* finds the smallest element of a vector */
49
50 const size_t N = v->size ;
51 const size_t stride = v->stride ;
52
53 BASE min = v->data[0 * stride];
54 size_t i;
55
56 for (i = 0; i < N; i++)
57 {
58 BASE x = v->data[i*stride];
59 if (x < min)
60 min = x;
61 #ifdef FP
62 if (isnan (x))
63 return x;
64 #endif
65 }
66
67 return min;
68 }
69
70 void
71 FUNCTION(gsl_vector,minmax) (const TYPE(gsl_vector) * v,
72 BASE * min_out,
73 BASE * max_out)
74 {
75 /* finds the smallest and largest elements of a vector */
76
77 const size_t N = v->size ;
78 const size_t stride = v->stride ;
79
80 BASE max = v->data[0 * stride];
81 BASE min = v->data[0 * stride];
82
83 size_t i;
84
85 for (i = 0; i < N; i++)
86 {
87 BASE x = v->data[i*stride];
88 if (x < min)
89 {
90 min = x;
91 }
92 if (x > max)
93 {
94 max = x;
95 }
96 #ifdef FP
97 if (isnan (x))
98 {
99 min = x;
100 max = x;
101 break;
102 }
103 #endif
104 }
105
106 *min_out = min;
107 *max_out = max;
108 }
109
110
111 size_t
112 FUNCTION(gsl_vector,max_index) (const TYPE(gsl_vector) * v)
113 {
114 /* finds the largest element of a vector */
115
116 const size_t N = v->size ;
117 const size_t stride = v->stride ;
118
119 BASE max = v->data[0 * stride];
120 size_t imax = 0;
121 size_t i;
122
123 for (i = 0; i < N; i++)
124 {
125 BASE x = v->data[i*stride];
126 if (x > max)
127 {
128 max = x;
129 imax = i;
130 }
131 #ifdef FP
132 if (isnan (x))
133 {
134 return i;
135 }
136 #endif
137 }
138
139 return imax;
140 }
141
142 size_t
143 FUNCTION(gsl_vector,min_index) (const TYPE(gsl_vector) * v)
144 {
145 /* finds the smallest element of a vector */
146
147 const size_t N = v->size ;
148 const size_t stride = v->stride ;
149
150 BASE min = v->data[0 * stride];
151 size_t imin = 0;
152 size_t i;
153
154 for (i = 0; i < N; i++)
155 {
156 BASE x = v->data[i*stride];
157 if (x < min)
158 {
159 min = x;
160 imin = i;
161 }
162 #ifdef FP
163 if (isnan (x))
164 {
165 return i;
166 }
167 #endif
168 }
169
170 return imin;
171 }
172
173
174 void
175 FUNCTION(gsl_vector,minmax_index) (const TYPE(gsl_vector) * v,
176 size_t * imin_out,
177 size_t * imax_out)
178 {
179 /* finds the smallest and largest elements of a vector */
180
181 const size_t N = v->size ;
182 const size_t stride = v->stride ;
183
184 size_t imin = 0, imax = 0;
185 BASE max = v->data[0 * stride];
186 BASE min = v->data[0 * stride];
187
188 size_t i;
189
190 for (i = 0; i < N; i++)
191 {
192 BASE x = v->data[i*stride];
193 if (x < min)
194 {
195 min = x;
196 imin = i;
197 }
198 if (x > max)
199 {
200 max = x;
201 imax = i;
202 }
203 #ifdef FP
204 if (isnan (x))
205 {
206 imin = i;
207 imax = i;
208 break;
209 }
210 #endif
211 }
212
213 *imin_out = imin;
214 *imax_out = imax;
215 }
216
217