1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2006, 2010-2012 Free Software Foundation, Inc.
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.
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.
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/>. */
17 #ifndef LIBPSPP_FLOAT_FORMAT_H
18 #define LIBPSPP_FLOAT_FORMAT_H 1
25 #include "libpspp/compiler.h"
27 /* A floating-point format. */
30 /* IEEE 754 formats. */
31 FLOAT_IEEE_SINGLE_LE, /* 32 bit, little endian. */
32 FLOAT_IEEE_SINGLE_BE, /* 32 bit, big endian. */
33 FLOAT_IEEE_DOUBLE_LE, /* 64 bit, little endian. */
34 FLOAT_IEEE_DOUBLE_BE, /* 64 bit, big endian. */
37 FLOAT_VAX_F, /* 32 bit VAX F format. */
38 FLOAT_VAX_D, /* 64 bit VAX D format. */
39 FLOAT_VAX_G, /* 64 bit VAX G format. */
41 /* IBM z architecture (390) hexadecimal formats. */
42 FLOAT_Z_SHORT, /* 32 bit format. */
43 FLOAT_Z_LONG, /* 64 bit format. */
45 /* Formats useful for testing. */
46 FLOAT_FP, /* Neutral intermediate format. */
47 FLOAT_HEX, /* C99 hexadecimal floating constant. */
49 #ifdef WORDS_BIGENDIAN
50 FLOAT_NATIVE_FLOAT = FLOAT_IEEE_SINGLE_BE,
51 FLOAT_NATIVE_DOUBLE = FLOAT_IEEE_DOUBLE_BE,
52 FLOAT_NATIVE_32_BIT = FLOAT_IEEE_SINGLE_BE,
53 FLOAT_NATIVE_64_BIT = FLOAT_IEEE_DOUBLE_BE
55 FLOAT_NATIVE_FLOAT = FLOAT_IEEE_SINGLE_LE,
56 FLOAT_NATIVE_DOUBLE = FLOAT_IEEE_DOUBLE_LE,
57 FLOAT_NATIVE_32_BIT = FLOAT_IEEE_SINGLE_LE,
58 FLOAT_NATIVE_64_BIT = FLOAT_IEEE_DOUBLE_LE
62 static inline uint64_t double_to_ieee64le (double x);
63 static inline double ieee64le_to_double (uint64_t x);
65 void float_convert (enum float_format, const void *,
66 enum float_format, void *);
68 double float_get_double (enum float_format, const void *);
70 size_t float_get_size (enum float_format) PURE_FUNCTION;
72 int float_identify (double expected_value, const void *, size_t,
73 enum float_format *best_guess);
75 double float_get_lowest (void);
77 static inline uint64_t
78 double_to_ieee64le (double x)
82 #if FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_LE
83 memcpy (&y, &x, sizeof y);
84 #elif FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_BE
85 memcpy (&y, &x, sizeof y);
88 float_convert (&x, FLOAT_NATIVE_DOUBLE, &y, FLOAT_IEEE_DOUBLE_LE);
95 ieee64le_to_double (uint64_t x)
99 #if FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_LE
100 memcpy (&y, &x, sizeof y);
101 #elif FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_BE
103 memcpy (&y, &x, sizeof y);
105 float_convert (&x, FLOAT_IEEE_DOUBLE_LE, &y, FLOAT_NATIVE_DOUBLE);
111 #endif /* float-format.h */