1 /*
2 
3 -Procedure intmin_c ( Smallest integer number )
4 
5 -Abstract
6 
7    Return the value of the smallest (negative) number representable
8    in a SpiceInt variable.
9 
10 -Disclaimer
11 
12    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
13    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
14    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
15    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
16    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
17    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
18    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
19    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
20    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
21    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
22 
23    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
24    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
25    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
26    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
27    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
28    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
29 
30    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
31    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
32    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
33    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
34 
35 -Required_Reading
36 
37    None.
38 
39 -Keywords
40 
41    CONSTANTS
42 
43 */
44 
45    #include "SpiceUsr.h"
46 
intmin_c()47    SpiceInt intmin_c ()
48 
49 /*
50 
51 -Brief_I/O
52 
53    The function returns the value of the smallest (negative) number
54    that can be represented in a SpiceInt variable.
55 
56 -Detailed_Input
57 
58    None.
59 
60 -Detailed_Output
61 
62    The function returns the value of the smallest (negative) number
63    that can be represented in an SpiceInt variable, where SpiceInt
64    is a typedef defined in SpiceZdf.h.
65 
66    The returned value will be less than or equal to -2147483647.
67    See the Particulars section for details.
68 
69 -Parameters
70 
71    None.
72 
73 -Exceptions
74 
75    Error free.
76 
77 -Files
78 
79    None.
80 
81 -Particulars
82 
83    The typedef SpiceInt is used throughout the CSPICE API to refer to
84    integers; the precise type of integer is platform-dependent.  A
85    SpiceInt always maps to the same type as does the f2c typedef
86    integer.
87 
88    When translating Fortran code, f2c maps Fortran variables of type
89    INTEGER to C variables of type "integer," where integer is a typedef
90    defined in the f2c header file f2c.h.  On all supported platforms,
91    Fortran INTEGERS occupy at least 32 bits.  On most platforms, this
92    means that the typedef integer translates to type long.  There are
93    some exceptional platforms on which an integer translates to type
94    int.  The mapping must provide compatibility with the f2c typedef
95    doublereal:  integers must occupy half the storage of doublereals in
96    order for these types to correctly represent the Fortran types
97    INTEGER and DOUBLE PRECISION.
98 
99    On systems where the typedef integer maps to type long, the return
100    value is defined by the macro LONG_MIN from the ANSI standard header
101    file limits.h. According to the ANSI standard, LONG_MIN must be no
102    greater than
103 
104       -2147483647
105 
106    This is
107 
108            31
109       - ( 2   - 1 )
110 
111    On systems where the typedef integer maps to type int, the value is
112    defined by the macro INT_MIN from the ANSI standard header file
113    limits.h. According to the ANSI standard, INT_MIN must be no greater
114    than
115 
116       -32767
117 
118    This is
119 
120           15
121       -( 2   - 1 )
122 
123    In practice however, the typedef integer will map to type int only
124    if ints occupy at least four bytes, so the value of INT_MIN will
125    actually be no greater than -2147483647.
126 
127 
128 -Examples
129 
130    The following code fragment illustrates the use of intmin_c.
131 
132       /.
133       Separate a double into integer and fractional components.
134       If the integer component is out of range, avoid overflow
135       by making it as large as possible.
136       ./
137       #include <math.h>
138                .
139                .
140                .
141       fract = modf ( dvalue, &integralDP );
142 
143       if (  integralDP  >  (double)intmax_c()  )
144       {
145          ivalue = intmax_c();
146       }
147       else if (  integralDP  <  (double)intmin_c()  )
148       {
149          ivalue = intmin_c();
150       }
151       else
152       {
153          ivalue = (long)( integralDP );
154       }
155 
156 
157 -Restrictions
158 
159    None.
160 
161 -Literature_References
162 
163    None.
164 
165 -Author_and_Institution
166 
167    N.J. Bachman    (JPL)
168    W.L. Taber      (JPL)
169    I.M. Underwood  (JPL)
170 
171 -Version
172 
173    -CSPICE Version 1.0.0, 29-JAN-1999 (NJB)
174 
175 -Index_Entries
176 
177    smallest integer number
178 
179 -&
180 */
181 
182 { /* Begin intmin_c */
183 
184 
185    /*
186    Static variables
187    */
188 
189    static SpiceBoolean            first = SPICETRUE;
190    static SpiceInt                value;
191 
192 
193 
194    if ( first )
195    {
196       value = intmin_();
197       first = SPICEFALSE;
198    }
199 
200    return ( value );
201 
202 
203 } /* End intmin_c */
204 
205