X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Ffloat-format.c;h=36cc0af3c8c3119fe7a13e13e1f35e2141460dd8;hb=b779cc2fe07d6e8e66aad413e4644e8e124c65ff;hp=7d65375ada731657a8ea50c221d843f8dacdb21e;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp diff --git a/src/libpspp/float-format.c b/src/libpspp/float-format.c index 7d65375ada..36cc0af3c8 100644 --- a/src/libpspp/float-format.c +++ b/src/libpspp/float-format.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006 Free Software Foundation, Inc. + 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 @@ -16,18 +16,17 @@ #include -#include +#include "libpspp/float-format.h" +#include #include #include #include +#include -#include -#include -#include +#include "libpspp/assertion.h" +#include "libpspp/integer-format.h" -#include "error.h" -#include /* Neutral intermediate representation for binary floating-point numbers. */ struct fp @@ -106,6 +105,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 @@ -177,6 +186,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; +} /* Returns CNT bits in X starting from the given bit OFS. */ static inline uint64_t @@ -667,7 +694,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);