1 /* 2 3 -Procedure mind_c ( Minimum of a set of double precision values ) 4 5 -Abstract 6 7 Find the minimum of a set of double precision values. 8 9 -Disclaimer 10 11 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 12 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 13 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 14 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 15 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 16 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 17 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 18 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 19 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 20 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 21 22 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 23 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 24 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 25 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 26 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 27 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 28 29 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 30 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 31 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 32 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 33 34 -Required_Reading 35 36 PLANES 37 38 -Keywords 39 40 GEOMETRY 41 MATH 42 PLANE 43 44 */ 45 #include <stdarg.h> 46 #include "SpiceUsr.h" 47 #include "SpiceZmc.h" 48 49 mind_c(SpiceInt n,...)50 SpiceDouble mind_c ( SpiceInt n, ... ) 51 52 /* 53 54 -Brief_I/O 55 56 Variable I/O Description 57 -------- --- -------------------------------------------------- 58 n I The number of double precision values to compare. 59 ... I The numbers to be compared, separated by commas. 60 61 -Detailed_Input 62 63 n is the number of double precision values in the set 64 whose minimum is to be determined. 65 66 ... represents a variable argument list. The number of 67 double precision values supplied must be that 68 indicated by n. The values are separated by commas. 69 70 Section 5.2.4.1 of the ANSI C Standard, titled 71 "Translation Limits," specifies that argument lists 72 containing at least 31 items must be supported. In 73 the interest of portability, no more than 30 74 double precision values should be supplied. 75 76 -Detailed_Output 77 78 The function returns the minimum of the set of input double precision 79 values. 80 81 -Parameters 82 83 None. 84 85 -Exceptions 86 87 Error free. 88 89 1) If n is less than 1, the value 0.0 is returned. 90 91 2) If the number of double precision values supplied does not match 92 the argument n, the action of this routine is not defined. 93 94 3) If the number of double precision values supplied exceeds 30, 95 the action of this routine is not defined. 96 97 -Files 98 99 None. 100 101 -Particulars 102 103 None. 104 105 -Examples 106 107 1) Find the minimum of four double precision values. 108 109 #include "SpiceUsr.h" 110 . 111 . 112 . 113 114 SpiceDouble min; 115 SpiceDouble a; 116 SpiceDouble b; 117 SpiceDouble c; 118 SpiceDouble d; 119 . 120 . 121 . 122 123 min = mind_c ( 4, a, b, c, d ); 124 125 126 -Restrictions 127 128 1) The ANSI C Standard specifies that argument lists containing 31 129 actual arguments must be supported. Larger sets of values may 130 not be handled properly by this routine. 131 132 -Literature_References 133 134 1) "American National Standard for Programming Languages---C." 135 Section 5.4.2.1, "Translation Limits," p. 13. 136 Published by American National Standards Institute, 137 11 West 42nd St., New York, NY 10035. Copyright 1990. 138 139 -Author_and_Institution 140 141 N.J. Bachman (JPL) 142 143 -Version 144 145 -CSPICE Version 1.0.1, 11-NOV-2006 (EDW) 146 147 Added "None." text to Particulars section, required for 148 API doc script (cspicehtml.pl) integrity checks. 149 150 -CSPICE Version 1.0.0, 16-SEP-1999 (NJB) 151 152 -Index_Entries 153 154 minimum of double precision values 155 156 -& 157 */ 158 159 { /* Begin mind_c */ 160 161 /* 162 Local variables 163 */ 164 165 SpiceDouble next; 166 SpiceDouble retval; 167 168 SpiceInt i; 169 170 171 /* 172 ap is the argument pointer. Its type va_list is declared in the 173 header stdarg.h. 174 */ 175 176 va_list ap; 177 178 179 180 /* 181 If there are no values to compare, return zero. 182 */ 183 184 if ( n < 1 ) 185 { 186 return ( 0.0 ); 187 } 188 189 /* 190 Initialize the argument pointer with the last named argument, namely 191 n. 192 */ 193 194 va_start ( ap, n ); 195 196 197 /* 198 Initialize the minimum with the first value. 199 */ 200 201 retval = va_arg ( ap, double ); 202 203 204 /* 205 Now compute a running minimum of the values, if there are more. 206 207 By the way, we capture the argument in the variable next rather than 208 make the va_arg call as a MinVal argument, because the MinVal macro 209 would make the va_arg call twice. 210 */ 211 212 for ( i = 1; i < n; i++ ) 213 { 214 next = va_arg ( ap, double ); 215 retval = MinVal ( retval, next ); 216 } 217 218 219 /* 220 Terminate the argument fetching process. 221 */ 222 223 va_end ( ap ); 224 225 226 /* 227 Return the value we've found. 228 */ 229 230 return ( retval ); 231 232 233 } /* End mind_c */ 234 235