| 1 | /* IEEE floating point support routines, for GDB, the GNU Debugger.
|
|---|
| 2 | Copyright (C) 1991, 1994, 1999, 2000 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GDB.
|
|---|
| 5 |
|
|---|
| 6 | This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 9 | (at your option) any later version.
|
|---|
| 10 |
|
|---|
| 11 | This program is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program; if not, write to the Free Software
|
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|---|
| 19 |
|
|---|
| 20 | #include "floatformat.h"
|
|---|
| 21 | #include <math.h> /* ldexp */
|
|---|
| 22 | #ifdef __STDC__
|
|---|
| 23 | #include <stddef.h>
|
|---|
| 24 | extern void *memcpy (void *s1, const void *s2, size_t n);
|
|---|
| 25 | extern void *memset (void *s, int c, size_t n);
|
|---|
| 26 | #else
|
|---|
| 27 | extern char *memcpy ();
|
|---|
| 28 | extern char *memset ();
|
|---|
| 29 | #endif
|
|---|
| 30 |
|
|---|
| 31 | /* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
|
|---|
| 32 | going to bother with trying to muck around with whether it is defined in
|
|---|
| 33 | a system header, what we do if not, etc. */
|
|---|
| 34 | #define FLOATFORMAT_CHAR_BIT 8
|
|---|
| 35 |
|
|---|
| 36 | /* floatformats for IEEE single and double, big and little endian. */
|
|---|
| 37 | const struct floatformat floatformat_ieee_single_big =
|
|---|
| 38 | {
|
|---|
| 39 | floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
|
|---|
| 40 | floatformat_intbit_no,
|
|---|
| 41 | "floatformat_ieee_single_big"
|
|---|
| 42 | };
|
|---|
| 43 | const struct floatformat floatformat_ieee_single_little =
|
|---|
| 44 | {
|
|---|
| 45 | floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
|
|---|
| 46 | floatformat_intbit_no,
|
|---|
| 47 | "floatformat_ieee_single_little"
|
|---|
| 48 | };
|
|---|
| 49 | const struct floatformat floatformat_ieee_double_big =
|
|---|
| 50 | {
|
|---|
| 51 | floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
|
|---|
| 52 | floatformat_intbit_no,
|
|---|
| 53 | "floatformat_ieee_double_big"
|
|---|
| 54 | };
|
|---|
| 55 | const struct floatformat floatformat_ieee_double_little =
|
|---|
| 56 | {
|
|---|
| 57 | floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
|
|---|
| 58 | floatformat_intbit_no,
|
|---|
| 59 | "floatformat_ieee_double_little"
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | /* floatformat for IEEE double, little endian byte order, with big endian word
|
|---|
| 63 | ordering, as on the ARM. */
|
|---|
| 64 |
|
|---|
| 65 | const struct floatformat floatformat_ieee_double_littlebyte_bigword =
|
|---|
| 66 | {
|
|---|
| 67 | floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
|
|---|
| 68 | floatformat_intbit_no,
|
|---|
| 69 | "floatformat_ieee_double_littlebyte_bigword"
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | const struct floatformat floatformat_i387_ext =
|
|---|
| 73 | {
|
|---|
| 74 | floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
|
|---|
| 75 | floatformat_intbit_yes,
|
|---|
| 76 | "floatformat_i387_ext"
|
|---|
| 77 | };
|
|---|
| 78 | const struct floatformat floatformat_m68881_ext =
|
|---|
| 79 | {
|
|---|
| 80 | /* Note that the bits from 16 to 31 are unused. */
|
|---|
| 81 | floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
|
|---|
| 82 | floatformat_intbit_yes,
|
|---|
| 83 | "floatformat_m68881_ext"
|
|---|
| 84 | };
|
|---|
| 85 | const struct floatformat floatformat_i960_ext =
|
|---|
| 86 | {
|
|---|
| 87 | /* Note that the bits from 0 to 15 are unused. */
|
|---|
| 88 | floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
|
|---|
| 89 | floatformat_intbit_yes,
|
|---|
| 90 | "floatformat_i960_ext"
|
|---|
| 91 | };
|
|---|
| 92 | const struct floatformat floatformat_m88110_ext =
|
|---|
| 93 | {
|
|---|
| 94 | floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
|
|---|
| 95 | floatformat_intbit_yes,
|
|---|
| 96 | "floatformat_m88110_ext"
|
|---|
| 97 | };
|
|---|
| 98 | const struct floatformat floatformat_m88110_harris_ext =
|
|---|
| 99 | {
|
|---|
| 100 | /* Harris uses raw format 128 bytes long, but the number is just an ieee
|
|---|
| 101 | double, and the last 64 bits are wasted. */
|
|---|
| 102 | floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52,
|
|---|
| 103 | floatformat_intbit_no,
|
|---|
| 104 | "floatformat_m88110_ext_harris"
|
|---|
| 105 | };
|
|---|
| 106 | const struct floatformat floatformat_arm_ext =
|
|---|
| 107 | {
|
|---|
| 108 | /* Bits 1 to 16 are unused. */
|
|---|
| 109 | floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
|
|---|
| 110 | floatformat_intbit_yes,
|
|---|
| 111 | "floatformat_arm_ext"
|
|---|
| 112 | };
|
|---|
| 113 | const struct floatformat floatformat_arm_ext_big =
|
|---|
| 114 | {
|
|---|
| 115 | /* Bits 1 to 16 are unused. */
|
|---|
| 116 | floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
|
|---|
| 117 | floatformat_intbit_yes,
|
|---|
| 118 | "floatformat_arm_ext_big"
|
|---|
| 119 | };
|
|---|
| 120 | const struct floatformat floatformat_arm_ext_littlebyte_bigword =
|
|---|
| 121 | {
|
|---|
| 122 | /* Bits 1 to 16 are unused. */
|
|---|
| 123 | floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
|
|---|
| 124 | floatformat_intbit_yes,
|
|---|
| 125 | "floatformat_arm_ext_littlebyte_bigword"
|
|---|
| 126 | };
|
|---|
| 127 | const struct floatformat floatformat_ia64_spill_big =
|
|---|
| 128 | {
|
|---|
| 129 | floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
|
|---|
| 130 | floatformat_intbit_yes,
|
|---|
| 131 | "floatformat_ia64_spill_big"
|
|---|
| 132 | };
|
|---|
| 133 | const struct floatformat floatformat_ia64_spill_little =
|
|---|
| 134 | {
|
|---|
| 135 | floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
|
|---|
| 136 | floatformat_intbit_yes,
|
|---|
| 137 | "floatformat_ia64_spill_little"
|
|---|
| 138 | };
|
|---|
| 139 | const struct floatformat floatformat_ia64_quad_big =
|
|---|
| 140 | {
|
|---|
| 141 | floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
|
|---|
| 142 | floatformat_intbit_no,
|
|---|
| 143 | "floatformat_ia64_quad_big"
|
|---|
| 144 | };
|
|---|
| 145 | const struct floatformat floatformat_ia64_quad_little =
|
|---|
| 146 | {
|
|---|
| 147 | floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
|
|---|
| 148 | floatformat_intbit_no,
|
|---|
| 149 | "floatformat_ia64_quad_little"
|
|---|
| 150 | };
|
|---|
| 151 | |
|---|
| 152 |
|
|---|
| 153 | static unsigned long get_field PARAMS ((unsigned char *,
|
|---|
| 154 | enum floatformat_byteorders,
|
|---|
| 155 | unsigned int,
|
|---|
| 156 | unsigned int,
|
|---|
| 157 | unsigned int));
|
|---|
| 158 |
|
|---|
| 159 | /* Extract a field which starts at START and is LEN bytes long. DATA and
|
|---|
| 160 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
|
|---|
| 161 | static unsigned long
|
|---|
| 162 | get_field (data, order, total_len, start, len)
|
|---|
| 163 | unsigned char *data;
|
|---|
| 164 | enum floatformat_byteorders order;
|
|---|
| 165 | unsigned int total_len;
|
|---|
| 166 | unsigned int start;
|
|---|
| 167 | unsigned int len;
|
|---|
| 168 | {
|
|---|
| 169 | unsigned long result;
|
|---|
| 170 | unsigned int cur_byte;
|
|---|
| 171 | int cur_bitshift;
|
|---|
| 172 |
|
|---|
| 173 | /* Start at the least significant part of the field. */
|
|---|
| 174 | cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
|
|---|
| 175 | if (order == floatformat_little)
|
|---|
| 176 | cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
|
|---|
| 177 | cur_bitshift =
|
|---|
| 178 | ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
|
|---|
| 179 | result = *(data + cur_byte) >> (-cur_bitshift);
|
|---|
| 180 | cur_bitshift += FLOATFORMAT_CHAR_BIT;
|
|---|
| 181 | if (order == floatformat_little)
|
|---|
| 182 | ++cur_byte;
|
|---|
| 183 | else
|
|---|
| 184 | --cur_byte;
|
|---|
| 185 |
|
|---|
| 186 | /* Move towards the most significant part of the field. */
|
|---|
| 187 | while ((unsigned int) cur_bitshift < len)
|
|---|
| 188 | {
|
|---|
| 189 | if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
|
|---|
| 190 | /* This is the last byte; zero out the bits which are not part of
|
|---|
| 191 | this field. */
|
|---|
| 192 | result |=
|
|---|
| 193 | (*(data + cur_byte) & ((1 << (len - cur_bitshift)) - 1))
|
|---|
| 194 | << cur_bitshift;
|
|---|
| 195 | else
|
|---|
| 196 | result |= *(data + cur_byte) << cur_bitshift;
|
|---|
| 197 | cur_bitshift += FLOATFORMAT_CHAR_BIT;
|
|---|
| 198 | if (order == floatformat_little)
|
|---|
| 199 | ++cur_byte;
|
|---|
| 200 | else
|
|---|
| 201 | --cur_byte;
|
|---|
| 202 | }
|
|---|
| 203 | return result;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | #ifndef min
|
|---|
| 207 | #define min(a, b) ((a) < (b) ? (a) : (b))
|
|---|
| 208 | #endif
|
|---|
| 209 |
|
|---|
| 210 | /* Convert from FMT to a double.
|
|---|
| 211 | FROM is the address of the extended float.
|
|---|
| 212 | Store the double in *TO. */
|
|---|
| 213 |
|
|---|
| 214 | void
|
|---|
| 215 | floatformat_to_double (fmt, from, to)
|
|---|
| 216 | const struct floatformat *fmt;
|
|---|
| 217 | char *from;
|
|---|
| 218 | double *to;
|
|---|
| 219 | {
|
|---|
| 220 | unsigned char *ufrom = (unsigned char *)from;
|
|---|
| 221 | double dto;
|
|---|
| 222 | long exponent;
|
|---|
| 223 | unsigned long mant;
|
|---|
| 224 | unsigned int mant_bits, mant_off;
|
|---|
| 225 | int mant_bits_left;
|
|---|
| 226 | int special_exponent; /* It's a NaN, denorm or zero */
|
|---|
| 227 |
|
|---|
| 228 | exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
|
|---|
| 229 | fmt->exp_start, fmt->exp_len);
|
|---|
| 230 | /* Note that if exponent indicates a NaN, we can't really do anything useful
|
|---|
| 231 | (not knowing if the host has NaN's, or how to build one). So it will
|
|---|
| 232 | end up as an infinity or something close; that is OK. */
|
|---|
| 233 |
|
|---|
| 234 | mant_bits_left = fmt->man_len;
|
|---|
| 235 | mant_off = fmt->man_start;
|
|---|
| 236 | dto = 0.0;
|
|---|
| 237 |
|
|---|
| 238 | special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan;
|
|---|
| 239 |
|
|---|
| 240 | /* Don't bias zero's, denorms or NaNs. */
|
|---|
| 241 | if (!special_exponent)
|
|---|
| 242 | exponent -= fmt->exp_bias;
|
|---|
| 243 |
|
|---|
| 244 | /* Build the result algebraically. Might go infinite, underflow, etc;
|
|---|
| 245 | who cares. */
|
|---|
| 246 |
|
|---|
| 247 | /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
|
|---|
| 248 | increment the exponent by one to account for the integer bit. */
|
|---|
| 249 |
|
|---|
| 250 | if (!special_exponent)
|
|---|
| 251 | {
|
|---|
| 252 | if (fmt->intbit == floatformat_intbit_no)
|
|---|
| 253 | dto = ldexp (1.0, exponent);
|
|---|
| 254 | else
|
|---|
| 255 | exponent++;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | while (mant_bits_left > 0)
|
|---|
| 259 | {
|
|---|
| 260 | mant_bits = min (mant_bits_left, 32);
|
|---|
| 261 |
|
|---|
| 262 | mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
|
|---|
| 263 | mant_off, mant_bits);
|
|---|
| 264 |
|
|---|
| 265 | dto += ldexp ((double)mant, exponent - mant_bits);
|
|---|
| 266 | exponent -= mant_bits;
|
|---|
| 267 | mant_off += mant_bits;
|
|---|
| 268 | mant_bits_left -= mant_bits;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | /* Negate it if negative. */
|
|---|
| 272 | if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
|
|---|
| 273 | dto = -dto;
|
|---|
| 274 | *to = dto;
|
|---|
| 275 | }
|
|---|
| 276 | |
|---|
| 277 |
|
|---|
| 278 | static void put_field PARAMS ((unsigned char *, enum floatformat_byteorders,
|
|---|
| 279 | unsigned int,
|
|---|
| 280 | unsigned int,
|
|---|
| 281 | unsigned int,
|
|---|
| 282 | unsigned long));
|
|---|
| 283 |
|
|---|
| 284 | /* Set a field which starts at START and is LEN bytes long. DATA and
|
|---|
| 285 | TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
|
|---|
| 286 | static void
|
|---|
| 287 | put_field (data, order, total_len, start, len, stuff_to_put)
|
|---|
| 288 | unsigned char *data;
|
|---|
| 289 | enum floatformat_byteorders order;
|
|---|
| 290 | unsigned int total_len;
|
|---|
| 291 | unsigned int start;
|
|---|
| 292 | unsigned int len;
|
|---|
| 293 | unsigned long stuff_to_put;
|
|---|
| 294 | {
|
|---|
| 295 | unsigned int cur_byte;
|
|---|
| 296 | int cur_bitshift;
|
|---|
| 297 |
|
|---|
| 298 | /* Start at the least significant part of the field. */
|
|---|
| 299 | cur_byte = (start + len) / FLOATFORMAT_CHAR_BIT;
|
|---|
| 300 | if (order == floatformat_little)
|
|---|
| 301 | cur_byte = (total_len / FLOATFORMAT_CHAR_BIT) - cur_byte - 1;
|
|---|
| 302 | cur_bitshift =
|
|---|
| 303 | ((start + len) % FLOATFORMAT_CHAR_BIT) - FLOATFORMAT_CHAR_BIT;
|
|---|
| 304 | *(data + cur_byte) &=
|
|---|
| 305 | ~(((1 << ((start + len) % FLOATFORMAT_CHAR_BIT)) - 1) << (-cur_bitshift));
|
|---|
| 306 | *(data + cur_byte) |=
|
|---|
| 307 | (stuff_to_put & ((1 << FLOATFORMAT_CHAR_BIT) - 1)) << (-cur_bitshift);
|
|---|
| 308 | cur_bitshift += FLOATFORMAT_CHAR_BIT;
|
|---|
| 309 | if (order == floatformat_little)
|
|---|
| 310 | ++cur_byte;
|
|---|
| 311 | else
|
|---|
| 312 | --cur_byte;
|
|---|
| 313 |
|
|---|
| 314 | /* Move towards the most significant part of the field. */
|
|---|
| 315 | while ((unsigned int) cur_bitshift < len)
|
|---|
| 316 | {
|
|---|
| 317 | if (len - cur_bitshift < FLOATFORMAT_CHAR_BIT)
|
|---|
| 318 | {
|
|---|
| 319 | /* This is the last byte. */
|
|---|
| 320 | *(data + cur_byte) &=
|
|---|
| 321 | ~((1 << (len - cur_bitshift)) - 1);
|
|---|
| 322 | *(data + cur_byte) |= (stuff_to_put >> cur_bitshift);
|
|---|
| 323 | }
|
|---|
| 324 | else
|
|---|
| 325 | *(data + cur_byte) = ((stuff_to_put >> cur_bitshift)
|
|---|
| 326 | & ((1 << FLOATFORMAT_CHAR_BIT) - 1));
|
|---|
| 327 | cur_bitshift += FLOATFORMAT_CHAR_BIT;
|
|---|
| 328 | if (order == floatformat_little)
|
|---|
| 329 | ++cur_byte;
|
|---|
| 330 | else
|
|---|
| 331 | --cur_byte;
|
|---|
| 332 | }
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | /* The converse: convert the double *FROM to an extended float
|
|---|
| 336 | and store where TO points. Neither FROM nor TO have any alignment
|
|---|
| 337 | restrictions. */
|
|---|
| 338 |
|
|---|
| 339 | void
|
|---|
| 340 | floatformat_from_double (fmt, from, to)
|
|---|
| 341 | const struct floatformat *fmt;
|
|---|
| 342 | double *from;
|
|---|
| 343 | char *to;
|
|---|
| 344 | {
|
|---|
| 345 | double dfrom;
|
|---|
| 346 | int exponent;
|
|---|
| 347 | double mant;
|
|---|
| 348 | unsigned int mant_bits, mant_off;
|
|---|
| 349 | int mant_bits_left;
|
|---|
| 350 | unsigned char *uto = (unsigned char *)to;
|
|---|
| 351 |
|
|---|
| 352 | memcpy (&dfrom, from, sizeof (dfrom));
|
|---|
| 353 | memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
|
|---|
| 354 | if (dfrom == 0)
|
|---|
| 355 | return; /* Result is zero */
|
|---|
| 356 | if (dfrom != dfrom)
|
|---|
| 357 | {
|
|---|
| 358 | /* From is NaN */
|
|---|
| 359 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
|
|---|
| 360 | fmt->exp_len, fmt->exp_nan);
|
|---|
| 361 | /* Be sure it's not infinity, but NaN value is irrel */
|
|---|
| 362 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
|
|---|
| 363 | 32, 1);
|
|---|
| 364 | return;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | /* If negative, set the sign bit. */
|
|---|
| 368 | if (dfrom < 0)
|
|---|
| 369 | {
|
|---|
| 370 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
|
|---|
| 371 | dfrom = -dfrom;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | /* How to tell an infinity from an ordinary number? FIXME-someday */
|
|---|
| 375 |
|
|---|
| 376 | mant = frexp (dfrom, &exponent);
|
|---|
| 377 | put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, fmt->exp_len,
|
|---|
| 378 | exponent + fmt->exp_bias - 1);
|
|---|
| 379 |
|
|---|
| 380 | mant_bits_left = fmt->man_len;
|
|---|
| 381 | mant_off = fmt->man_start;
|
|---|
| 382 | while (mant_bits_left > 0)
|
|---|
| 383 | {
|
|---|
| 384 | unsigned long mant_long;
|
|---|
| 385 | mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
|
|---|
| 386 |
|
|---|
| 387 | mant *= 4294967296.0;
|
|---|
| 388 | mant_long = (unsigned long)mant;
|
|---|
| 389 | mant -= mant_long;
|
|---|
| 390 |
|
|---|
| 391 | /* If the integer bit is implicit, then we need to discard it.
|
|---|
| 392 | If we are discarding a zero, we should be (but are not) creating
|
|---|
| 393 | a denormalized number which means adjusting the exponent
|
|---|
| 394 | (I think). */
|
|---|
| 395 | if ((unsigned int) mant_bits_left == fmt->man_len
|
|---|
| 396 | && fmt->intbit == floatformat_intbit_no)
|
|---|
| 397 | {
|
|---|
| 398 | mant_long &= 0x7fffffff;
|
|---|
| 399 | mant_bits -= 1;
|
|---|
| 400 | }
|
|---|
| 401 | else if (mant_bits < 32)
|
|---|
| 402 | {
|
|---|
| 403 | /* The bits we want are in the most significant MANT_BITS bits of
|
|---|
| 404 | mant_long. Move them to the least significant. */
|
|---|
| 405 | mant_long >>= 32 - mant_bits;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | put_field (uto, fmt->byteorder, fmt->totalsize,
|
|---|
| 409 | mant_off, mant_bits, mant_long);
|
|---|
| 410 | mant_off += mant_bits;
|
|---|
| 411 | mant_bits_left -= mant_bits;
|
|---|
| 412 | }
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 | #ifdef IEEE_DEBUG
|
|---|
| 417 |
|
|---|
| 418 | /* This is to be run on a host which uses IEEE floating point. */
|
|---|
| 419 |
|
|---|
| 420 | void
|
|---|
| 421 | ieee_test (n)
|
|---|
| 422 | double n;
|
|---|
| 423 | {
|
|---|
| 424 | double result;
|
|---|
| 425 | char exten[16];
|
|---|
| 426 |
|
|---|
| 427 | floatformat_to_double (&floatformat_ieee_double_big, &n, &result);
|
|---|
| 428 | if (n != result)
|
|---|
| 429 | printf ("Differ(to): %.20g -> %.20g\n", n, result);
|
|---|
| 430 | floatformat_from_double (&floatformat_ieee_double_big, &n, &result);
|
|---|
| 431 | if (n != result)
|
|---|
| 432 | printf ("Differ(from): %.20g -> %.20g\n", n, result);
|
|---|
| 433 |
|
|---|
| 434 | floatformat_from_double (&floatformat_m68881_ext, &n, exten);
|
|---|
| 435 | floatformat_to_double (&floatformat_m68881_ext, exten, &result);
|
|---|
| 436 | if (n != result)
|
|---|
| 437 | printf ("Differ(to+from): %.20g -> %.20g\n", n, result);
|
|---|
| 438 |
|
|---|
| 439 | #if IEEE_DEBUG > 1
|
|---|
| 440 | /* This is to be run on a host which uses 68881 format. */
|
|---|
| 441 | {
|
|---|
| 442 | long double ex = *(long double *)exten;
|
|---|
| 443 | if (ex != n)
|
|---|
| 444 | printf ("Differ(from vs. extended): %.20g\n", n);
|
|---|
| 445 | }
|
|---|
| 446 | #endif
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | int
|
|---|
| 450 | main ()
|
|---|
| 451 | {
|
|---|
| 452 | ieee_test (0.5);
|
|---|
| 453 | ieee_test (256.0);
|
|---|
| 454 | ieee_test (0.12345);
|
|---|
| 455 | ieee_test (234235.78907234);
|
|---|
| 456 | ieee_test (-512.0);
|
|---|
| 457 | ieee_test (-0.004321);
|
|---|
| 458 | return 0;
|
|---|
| 459 | }
|
|---|
| 460 | #endif
|
|---|