X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Ffloat-format.h;fp=src%2Flibpspp%2Ffloat-format.h;h=028a4e8d0c7ad711ac3135285f2a798567d2f6bc;hb=52c54183e360053b1845e46cb96cd44a0cf96040;hp=9cabf9bf2e228c0db8be76526096bc3c1694e4ba;hpb=2ca3267c1110bbff675c560b19d02defb96ee2f9;p=pspp diff --git a/src/libpspp/float-format.h b/src/libpspp/float-format.h index 9cabf9bf2e..028a4e8d0c 100644 --- a/src/libpspp/float-format.h +++ b/src/libpspp/float-format.h @@ -1,5 +1,5 @@ /* 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 @@ -17,7 +17,10 @@ #ifndef LIBPSPP_FLOAT_FORMAT_H #define LIBPSPP_FLOAT_FORMAT_H 1 +#include #include +#include +#include #include #include "libpspp/compiler.h" @@ -56,6 +59,9 @@ enum float_format #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 *); @@ -67,5 +73,39 @@ int float_identify (double expected_value, const void *, size_t, enum float_format *best_guess); double float_get_lowest (void); + +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 */