/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2010-2012 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
#ifndef LIBPSPP_FLOAT_FORMAT_H
#define LIBPSPP_FLOAT_FORMAT_H 1
+#include <byteswap.h>
#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
#include <stddef.h>
#include "libpspp/compiler.h"
#endif
};
+static inline uint64_t double_to_ieee64le (double x);
+static inline double ieee64le_to_double (uint64_t x);
+
void float_convert (enum float_format, const void *,
enum float_format, void *);
enum float_format *best_guess);
double float_get_lowest (void);
+\f
+static inline uint64_t
+double_to_ieee64le (double x)
+{
+ uint64_t y;
+
+#if FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_LE
+ memcpy (&y, &x, sizeof y);
+#elif FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_BE
+ memcpy (&y, &x, sizeof y);
+ y = bswap_64 (y);
+#else
+ float_convert (&x, FLOAT_NATIVE_DOUBLE, &y, FLOAT_IEEE_DOUBLE_LE);
+#endif
+
+ return y;
+}
+
+static inline double
+ieee64le_to_double (uint64_t x)
+{
+ double y;
+
+#if FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_LE
+ memcpy (&y, &x, sizeof y);
+#elif FLOAT_NATIVE_DOUBLE == FLOAT_IEEE_DOUBLE_BE
+ x = bswap_64 (x);
+ memcpy (&y, &x, sizeof y);
+#else
+ float_convert (&x, FLOAT_IEEE_DOUBLE_LE, &y, FLOAT_NATIVE_DOUBLE);
+#endif
+
+ return y;
+}
#endif /* float-format.h */