diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 2003-03-21 17:10:02 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2003-03-21 17:10:02 +0000 |
commit | 649eaf9bfd466d7e98f1ba41e57ac39f440c989e (patch) | |
tree | f92bcd0dd5b17043f1634195bcbf18c4df1df8da /gcc/java/jcf-dump.c | |
parent | c0510d84b7e1e57f475d27a3390b7177a1cf9d27 (diff) | |
download | gcc-649eaf9bfd466d7e98f1ba41e57ac39f440c989e.zip gcc-649eaf9bfd466d7e98f1ba41e57ac39f440c989e.tar.gz gcc-649eaf9bfd466d7e98f1ba41e57ac39f440c989e.tar.bz2 |
javaop.h (jfloat, jdouble): Make them structures mirroring the bit fields of IEEE float and double respectively.
* javaop.h (jfloat, jdouble): Make them structures mirroring
the bit fields of IEEE float and double respectively.
(JFLOAT_FINITE, JFLOAT_QNAN_MASK, JFLOAT_EXP_BIAS,
JDOUBLE_FINITE, JDOUBLE_QNAN_MASK, JDOUBLE_EXP_BIAS): New.
(union Word, union DWord): Delete.
(WORD_TO_FLOAT, WORDS_TO_DOUBLE): Update to match.
* gjavah.c (java_float_finite, java_double_finite, F_NAN_MASK,
D_NAN_MASK): Delete.
(jni_print_float, jni_print_double): New. Generate
hexadecimal floating constants.
(print_field_info): Use jni_print_float/double.
* jcf-dump.c: Include math.h. Use ldexp/frexp to assemble
finite floating point numbers for output; special case
non-finite floats.
From-SVN: r64671
Diffstat (limited to 'gcc/java/jcf-dump.c')
-rw-r--r-- | gcc/java/jcf-dump.c | 85 |
1 files changed, 74 insertions, 11 deletions
diff --git a/gcc/java/jcf-dump.c b/gcc/java/jcf-dump.c index 6d976e5..a87dd40 100644 --- a/gcc/java/jcf-dump.c +++ b/gcc/java/jcf-dump.c @@ -62,6 +62,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "version.h" #include <getopt.h> +#include <math.h> /* Outout file. */ FILE *out; @@ -504,24 +505,86 @@ print_constant (FILE *out, JCF *jcf, int index, int verbosity) break; case CONSTANT_Float: { - union - { - jfloat f; - int32 i; - } pun; - - pun.f = JPOOL_FLOAT (jcf, index); - fprintf (out, "%s%.10g", - verbosity > 0 ? "Float " : "", (double) pun.f); + jfloat fnum = JPOOL_FLOAT (jcf, index); + + if (verbosity > 0) + fputs ("Float ", out); + + if (fnum.negative) + putc ('-', out); + + if (JFLOAT_FINITE (fnum)) + { + int dummy; + int exponent = fnum.exponent - JFLOAT_EXP_BIAS; + double f; + uint32 mantissa = fnum.mantissa; + if (fnum.exponent == 0) + /* Denormal. */ + exponent++; + else + /* Normal; add the implicit bit. */ + mantissa |= ((uint32)1 << 23); + + f = frexp (mantissa, &dummy); + f = ldexp (f, exponent + 1); + fprintf (out, "%.10g", f); + } + else + { + if (fnum.mantissa == 0) + fputs ("Inf", out); + else if (fnum.mantissa & JFLOAT_QNAN_MASK) + fprintf (out, "QNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK)); + else + fprintf (out, "SNaN(%u)", (fnum.mantissa & ~JFLOAT_QNAN_MASK)); + } + if (verbosity > 1) - fprintf (out, ", bits = 0x%08lx", (long) pun.i); + fprintf (out, ", bits = 0x%08lx", JPOOL_UINT (jcf, index)); break; } case CONSTANT_Double: { jdouble dnum = JPOOL_DOUBLE (jcf, index); - fprintf (out, "%s%.20g", verbosity > 0 ? "Double " : "", dnum); + + if (verbosity > 0) + fputs ("Double ", out); + + if (dnum.negative) + putc ('-', out); + + if (JDOUBLE_FINITE (dnum)) + { + int dummy; + int exponent = dnum.exponent - JDOUBLE_EXP_BIAS; + double d; + uint64 mantissa = ((((uint64) dnum.mantissa0) << 32) + + dnum.mantissa1); + if (dnum.exponent == 0) + /* Denormal. */ + exponent++; + else + /* Normal; add the implicit bit. */ + mantissa |= ((uint64)1 << 52); + + d = frexp (mantissa, &dummy); + d = ldexp (d, exponent + 1); + fprintf (out, "%.20g", d); + } + else + { + uint64 mantissa = dnum.mantissa0 & ~JDOUBLE_QNAN_MASK; + mantissa = (mantissa << 32) + dnum.mantissa1; + + if (dnum.mantissa0 == 0 && dnum.mantissa1 == 0) + fputs ("Inf", out); + else if (dnum.mantissa0 & JDOUBLE_QNAN_MASK) + fprintf (out, "QNaN(%llu)", (unsigned long long)mantissa); + else + fprintf (out, "SNaN(%llu)", (unsigned long long)mantissa); + } if (verbosity > 1) { int32 hi, lo; |