aboutsummaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorDaniel Jacobowitz <drow@false.org>2003-09-15 20:14:39 +0000
committerDaniel Jacobowitz <drow@false.org>2003-09-15 20:14:39 +0000
commit3f2aacafdc2e8172de64e7aa47f7e9cec631b53c (patch)
tree42805ed20b3a9890fc36376c2101bbaffef43456 /libiberty
parentfca63fe805f2cc5dc02c57003376dfafb223bbcc (diff)
downloadgdb-3f2aacafdc2e8172de64e7aa47f7e9cec631b53c.zip
gdb-3f2aacafdc2e8172de64e7aa47f7e9cec631b53c.tar.gz
gdb-3f2aacafdc2e8172de64e7aa47f7e9cec631b53c.tar.bz2
* floatformat.c (floatformat_is_valid): New function.
(get_field, put_field): Correct comments.
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/floatformat.c39
2 files changed, 41 insertions, 3 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index e702593..a70872e 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+2003-09-15 Daniel Jacobowitz <drow@mvista.com>
+
+ * floatformat.c (floatformat_is_valid): New function.
+ (get_field, put_field): Correct comments.
+
2003-09-06 Josef Zlomek <zlomekj@suse.cz>
* fibheap.c (fibheap_replace_key_data): Change type of OKEY to
diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c
index d69024f..b892dbe 100644
--- a/libiberty/floatformat.c
+++ b/libiberty/floatformat.c
@@ -1,5 +1,5 @@
/* IEEE floating point support routines, for GDB, the GNU Debugger.
- Copyright (C) 1991, 1994, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1994, 1999, 2000, 2003 Free Software Foundation, Inc.
This file is part of GDB.
@@ -149,7 +149,7 @@ static unsigned long get_field PARAMS ((unsigned char *,
unsigned int,
unsigned int));
-/* Extract a field which starts at START and is LEN bytes long. DATA and
+/* Extract a field which starts at START and is LEN bits long. DATA and
TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
static unsigned long
get_field (data, order, total_len, start, len)
@@ -273,7 +273,7 @@ static void put_field PARAMS ((unsigned char *, enum floatformat_byteorders,
unsigned int,
unsigned long));
-/* Set a field which starts at START and is LEN bytes long. DATA and
+/* Set a field which starts at START and is LEN bits long. DATA and
TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
static void
put_field (data, order, total_len, start, len, stuff_to_put)
@@ -404,6 +404,39 @@ floatformat_from_double (fmt, from, to)
}
}
+/* Return non-zero iff the data at FROM is a valid number in format FMT. */
+
+int
+floatformat_is_valid (fmt, from)
+ const struct floatformat *fmt;
+ char *from;
+{
+ if (fmt == &floatformat_i387_ext)
+ {
+ /* In the i387 double-extended format, if the exponent is all
+ ones, then the integer bit must be set. If the exponent
+ is neither 0 nor ~0, the intbit must also be set. Only
+ if the exponent is zero can it be zero, and then it must
+ be zero. */
+ unsigned long exponent, int_bit;
+ unsigned char *ufrom = (unsigned char *) from;
+
+ exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+ int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->man_start, 1);
+
+ if ((exponent == 0) != (int_bit == 0))
+ return 0;
+ else
+ return 1;
+ }
+
+ /* Other formats with invalid representations should be added
+ here. */
+ return 1;
+}
+
#ifdef IEEE_DEBUG