float-format: Remove unused functions.
[pspp] / src / libpspp / float-format.c
index 81b901f84514314167df4104ef9aa8def9720a9f..03d8c99062d7af3be1e20bc1af7e4d509d9c2eef 100644 (file)
@@ -1,35 +1,32 @@
-/* PSPP - computes sample statistics.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2006, 2011 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 
-#include <libpspp/float-format.h>
+#include "libpspp/float-format.h"
 
+#include <byteswap.h>
 #include <ctype.h>
 #include <inttypes.h>
 #include <stdlib.h>
+#include <string.h>
 
-#include <libpspp/assertion.h>
-#include <libpspp/integer-format.h>
-#include <libpspp/str.h>
+#include "libpspp/assertion.h"
+#include "libpspp/integer-format.h"
 
-#include "error.h"
-#include <byteswap.h>
 \f
 /* Neutral intermediate representation for binary floating-point numbers. */
 struct fp
@@ -71,11 +68,9 @@ struct fp
 static void extract_number (enum float_format, const void *, struct fp *);
 static void assemble_number (enum float_format, struct fp *, void *);
 
-static inline uint16_t get_uint16 (const void *);
 static inline uint32_t get_uint32 (const void *);
 static inline uint64_t get_uint64 (const void *);
 
-static inline void put_uint16 (uint16_t, void *);
 static inline void put_uint32 (uint32_t, void *);
 static inline void put_uint64 (uint64_t, void *);
 
@@ -108,6 +103,16 @@ float_convert (enum float_format from, const void *src,
     }
 }
 
+/* Converts SRC from format FROM to a native double and returns
+   the double. */
+double
+float_get_double (enum float_format from, const void *src)
+{
+  double dst;
+  float_convert (from, src, FLOAT_NATIVE_DOUBLE, &dst);
+  return dst;
+}
+
 /* Returns the number of bytes in a number in the given
    FORMAT. */
 size_t
@@ -179,6 +184,24 @@ float_identify (double expected_value, const void *number, size_t length,
       }
   return match_cnt;
 }
+
+/* Returns the double value that is just greater than -DBL_MAX,
+   which in PSPP syntax files is called LOWEST and used as the
+   low end of numeric ranges that are supposed to be unbounded on
+   the low end, as in the missing value set created by,
+   e.g. MISSING VALUES X(LOWEST THRU 5).  (-DBL_MAX is used for
+   SYSMIS so it is not available for LOWEST.) */
+double
+float_get_lowest (void)
+{
+  struct fp fp;
+  double x;
+
+  fp.class = LOWEST;
+  fp.sign = POSITIVE;
+  assemble_number (FLOAT_NATIVE_DOUBLE, &fp, &x);
+  return x;
+}
 \f
 /* Returns CNT bits in X starting from the given bit OFS. */
 static inline uint64_t
@@ -190,16 +213,6 @@ get_bits (uint64_t x, int ofs, int cnt)
   return (x >> ofs) & ((UINT64_C(1) << cnt) - 1);
 }
 
-/* Returns the 16-bit unsigned integer at P,
-   which need not be aligned. */
-static inline uint16_t
-get_uint16 (const void *p)
-{
-  uint16_t x;
-  memcpy (&x, p, sizeof x);
-  return x;
-}
-
 /* Returns the 32-bit unsigned integer at P,
    which need not be aligned. */
 static inline uint32_t
@@ -220,14 +233,6 @@ get_uint64 (const void *p)
   return x;
 }
 
-/* Stores 16-bit unsigned integer X at P,
-   which need not be aligned. */
-static inline void
-put_uint16 (uint16_t x, void *p)
-{
-  memcpy (p, &x, sizeof x);
-}
-
 /* Stores 32-bit unsigned integer X at P,
    which need not be aligned. */
 static inline void
@@ -244,30 +249,6 @@ put_uint64 (uint64_t x, void *p)
   memcpy (p, &x, sizeof x);
 }
 
-/* Returns NATIVE converted to a form that, when stored in
-   memory, will be in little-endian byte order. */
-static inline uint16_t
-native_to_le16 (uint16_t native)
-{
-  return INTEGER_NATIVE == INTEGER_LSB_FIRST ? native : bswap_16 (native);
-}
-
-/* Returns NATIVE converted to a form that, when stored in
-   memory, will be in big-endian byte order. */
-static inline uint16_t
-native_to_be16 (uint16_t native)
-{
-  return INTEGER_NATIVE == INTEGER_MSB_FIRST ? native : bswap_16 (native);
-}
-
-/* Returns NATIVE converted to a form that, when stored in
-   memory, will be in VAX-endian byte order. */
-static inline uint16_t
-native_to_vax16 (uint16_t native)
-{
-  return native_to_le16 (native);
-}
-
 /* Returns NATIVE converted to a form that, when stored in
    memory, will be in little-endian byte order. */
 static inline uint32_t
@@ -320,30 +301,6 @@ native_to_vax64 (uint64_t native)
                          ((native & UINT64_C(0x0000000000ff00ff)) << 40));
 }
 
-/* Given LE, obtained from memory in little-endian format,
-   returns its value. */
-static inline uint16_t
-le_to_native16 (uint16_t le)
-{
-  return INTEGER_NATIVE == INTEGER_LSB_FIRST ? le : bswap_16 (le);
-}
-
-/* Given BE, obtained from memory in big-endian format, returns
-   its value. */
-static inline uint16_t
-be_to_native16 (uint16_t be)
-{
-  return INTEGER_NATIVE == INTEGER_MSB_FIRST ? be : bswap_16 (be);
-}
-
-/* Given VAX, obtained from memory in VAX-endian format, returns
-   its value. */
-static inline uint16_t
-vax_to_native16 (uint16_t vax)
-{
-  return le_to_native16 (vax);
-}
-
 /* Given LE, obtained from memory in little-endian format,
    returns its value. */
 static inline uint32_t
@@ -669,7 +626,7 @@ assemble_number (enum float_format type, struct fp *fp, void *number)
       break;
 
     case FLOAT_Z_SHORT:
-      put_uint64 (native_to_be32 (assemble_z (fp, 7, 24)), number);
+      put_uint32 (native_to_be32 (assemble_z (fp, 7, 24)), number);
       break;
     case FLOAT_Z_LONG:
       put_uint64 (native_to_be64 (assemble_z (fp, 7, 56)), number);