comparison libiberty/floatformat.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* IEEE floating point support routines, for GDB, the GNU Debugger. 1 /* IEEE floating point support routines, for GDB, the GNU Debugger.
2 Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006, 2010 2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 3
5 This file is part of GDB. 4 This file is part of GDB.
6 5
7 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
17 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20 19
21 /* This is needed to pick up the NAN macro on some systems. */ 20 /* This is needed to pick up the NAN macro on some systems. */
21 #ifndef _GNU_SOURCE
22 #define _GNU_SOURCE 22 #define _GNU_SOURCE
23 #endif
23 24
24 #ifdef HAVE_CONFIG_H 25 #ifdef HAVE_CONFIG_H
25 #include "config.h" 26 #include "config.h"
26 #endif 27 #endif
27 28
369 return 0; 370 return 0;
370 return !mant_bits_set (hfmt, ufrom + 8); 371 return !mant_bits_set (hfmt, ufrom + 8);
371 } 372 }
372 } 373 }
373 374
374 const struct floatformat floatformat_ibm_long_double = 375 const struct floatformat floatformat_ibm_long_double_big =
375 { 376 {
376 floatformat_big, 128, 0, 1, 11, 1023, 2047, 12, 52, 377 floatformat_big, 128, 0, 1, 11, 1023, 2047, 12, 52,
377 floatformat_intbit_no, 378 floatformat_intbit_no,
378 "floatformat_ibm_long_double", 379 "floatformat_ibm_long_double_big",
379 floatformat_ibm_long_double_is_valid, 380 floatformat_ibm_long_double_is_valid,
380 &floatformat_ieee_double_big 381 &floatformat_ieee_double_big
382 };
383
384 const struct floatformat floatformat_ibm_long_double_little =
385 {
386 floatformat_little, 128, 0, 1, 11, 1023, 2047, 12, 52,
387 floatformat_intbit_no,
388 "floatformat_ibm_long_double_little",
389 floatformat_ibm_long_double_is_valid,
390 &floatformat_ieee_double_little
381 }; 391 };
382 392
383 393
384 #ifndef min 394 #ifndef min
385 #define min(a, b) ((a) < (b) ? (a) : (b)) 395 #define min(a, b) ((a) < (b) ? (a) : (b))
461 double dto; 471 double dto;
462 long exponent; 472 long exponent;
463 unsigned long mant; 473 unsigned long mant;
464 unsigned int mant_bits, mant_off; 474 unsigned int mant_bits, mant_off;
465 int mant_bits_left; 475 int mant_bits_left;
466 int special_exponent; /* It's a NaN, denorm or zero */
467 476
468 /* Split values are not handled specially, since the top half has 477 /* Split values are not handled specially, since the top half has
469 the correctly rounded double value (in the only supported case of 478 the correctly rounded double value (in the only supported case of
470 split values). */ 479 split values). */
471 480
501 510
502 mant_bits_left = fmt->man_len; 511 mant_bits_left = fmt->man_len;
503 mant_off = fmt->man_start; 512 mant_off = fmt->man_start;
504 dto = 0.0; 513 dto = 0.0;
505 514
506 special_exponent = exponent == 0 || (unsigned long) exponent == fmt->exp_nan;
507
508 /* Don't bias zero's, denorms or NaNs. */
509 if (!special_exponent)
510 exponent -= fmt->exp_bias;
511
512 /* Build the result algebraically. Might go infinite, underflow, etc; 515 /* Build the result algebraically. Might go infinite, underflow, etc;
513 who cares. */ 516 who cares. */
514 517
515 /* If this format uses a hidden bit, explicitly add it in now. Otherwise, 518 /* For denorms use minimum exponent. */
516 increment the exponent by one to account for the integer bit. */ 519 if (exponent == 0)
517 520 exponent = 1 - fmt->exp_bias;
518 if (!special_exponent) 521 else
519 { 522 {
523 exponent -= fmt->exp_bias;
524
525 /* If this format uses a hidden bit, explicitly add it in now.
526 Otherwise, increment the exponent by one to account for the
527 integer bit. */
528
520 if (fmt->intbit == floatformat_intbit_no) 529 if (fmt->intbit == floatformat_intbit_no)
521 dto = ldexp (1.0, exponent); 530 dto = ldexp (1.0, exponent);
522 else 531 else
523 exponent++; 532 exponent++;
524 } 533 }
528 mant_bits = min (mant_bits_left, 32); 537 mant_bits = min (mant_bits_left, 32);
529 538
530 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, 539 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
531 mant_off, mant_bits); 540 mant_off, mant_bits);
532 541
533 /* Handle denormalized numbers. FIXME: What should we do for 542 dto += ldexp ((double) mant, exponent - mant_bits);
534 non-IEEE formats? */ 543 exponent -= mant_bits;
535 if (special_exponent && exponent == 0 && mant != 0)
536 dto += ldexp ((double)mant,
537 (- fmt->exp_bias
538 - mant_bits
539 - (mant_off - fmt->man_start)
540 + 1));
541 else
542 dto += ldexp ((double)mant, exponent - mant_bits);
543 if (exponent != 0)
544 exponent -= mant_bits;
545 mant_off += mant_bits; 544 mant_off += mant_bits;
546 mant_bits_left -= mant_bits; 545 mant_bits_left -= mant_bits;
547 } 546 }
548 547
549 /* Negate it if negative. */ 548 /* Negate it if negative. */
754 int 753 int
755 main (void) 754 main (void)
756 { 755 {
757 ieee_test (0.0); 756 ieee_test (0.0);
758 ieee_test (0.5); 757 ieee_test (0.5);
758 ieee_test (1.1);
759 ieee_test (256.0); 759 ieee_test (256.0);
760 ieee_test (0.12345); 760 ieee_test (0.12345);
761 ieee_test (234235.78907234); 761 ieee_test (234235.78907234);
762 ieee_test (-512.0); 762 ieee_test (-512.0);
763 ieee_test (-0.004321); 763 ieee_test (-0.004321);