353141b98858cb1bdf31ec9d32792b29487fafc1
[pspp-builds.git] / src / val.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at 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., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !val_h
21 #define val_h 1
22
23 #include <float.h>
24 #include "config.h"
25
26 /* Values. */
27
28 /* Max length of a short string value, generally 8 chars. */
29 #define MAX_SHORT_STRING ((SIZEOF_DOUBLE)>=8 ? ((SIZEOF_DOUBLE)+1)/2*2 : 8)
30 #define MIN_LONG_STRING (MAX_SHORT_STRING+1)
31
32 /* Max string length. */
33 #define MAX_STRING 255
34
35 /* FYI: It is a bad situation if sizeof(flt64) < MAX_SHORT_STRING:
36    then short string missing values can be truncated in system files
37    because there's only room for as many characters as can fit in a
38    flt64. */
39 #if MAX_SHORT_STRING > 8
40 #error MAX_SHORT_STRING must be less than 8.
41 #endif
42
43 /* Special values. */
44 #define SYSMIS (-DBL_MAX)
45 #define LOWEST second_lowest_value
46 #define HIGHEST DBL_MAX
47
48 /* Describes one value, which is either a floating-point number or a
49    short string. */
50 union value
51   {
52     /* A numeric value. */
53     double f;
54
55     /* A short-string value. */
56     unsigned char s[MAX_SHORT_STRING];
57
58     /* Used by evaluate_expression() to return a string result.
59        As currently implemented, it's a pointer to a dynamic
60        buffer in the appropriate expression.
61
62        Also used by the AGGREGATE procedure in handling string
63        values. */
64     unsigned char *c;
65   };
66
67 /* Maximum number of `union value's in a single number or string
68    value. */
69 #define MAX_ELEMS_PER_VALUE (MAX_STRING / sizeof (union value) + 1)
70
71 int compare_values (const union value *a, const union value *b, int width);
72
73 unsigned  hash_value(const union value  *v, int width);
74
75
76
77 #endif /* !val_h */