magic-elimination.patch from patch #6230.
[pspp-builds.git] / src / data / value.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #if !value_h
18 #define value_h 1
19
20 #include <float.h>
21 #include <libpspp/float-format.h>
22 #include <libpspp/misc.h>
23 #include "minmax.h"
24 #include <config.h>
25
26 /* Values. */
27
28 /* "Short" strings, which are generally those no more than 8
29    characters wide, can participate in more operations than
30    longer strings. */
31 #define MAX_SHORT_STRING (MAX (ROUND_UP (SIZEOF_DOUBLE, 2), 8))
32 #define MIN_LONG_STRING (MAX_SHORT_STRING + 1)
33 #define MAX_STRING 32767
34
35 /* Special values. */
36 #define SYSMIS (-DBL_MAX)
37 #define LOWEST (float_get_lowest ())
38 #define HIGHEST DBL_MAX
39
40 /* Number of "union value"s required for a variable of the given
41    WIDTH. */
42 static inline size_t
43 value_cnt_from_width (int width)
44 {
45   return width == 0 ? 1 : DIV_RND_UP (width, MAX_SHORT_STRING);
46 }
47
48 /* A numeric or short string value.
49    Multiple consecutive values represent a long string. */
50 union value
51   {
52     double f;
53     char s[MAX_SHORT_STRING];
54   };
55
56 union value *value_dup (const union value *, int width);
57 union value *value_create (int width);
58
59 int compare_values (const union value *, const union value *, int width);
60 unsigned hash_value (const union value  *, int width);
61
62 void value_copy (union value *, const union value *, int width);
63 void value_set_missing (union value *, int width);
64
65 #endif /* !value.h */