Article View: gnu.gdb.bug
Article #8825GDB 4.7 does not add `float' + `float' the same way that C does
From: Paul Eggert
Date: Sun, 25 Oct 1992 18:35
Date: Sun, 25 Oct 1992 18:35
123 lines
4545 bytes
4545 bytes
GDB 4.7 (SunOS 4.1.2, sparc) does not add two `float' values the same way
that ANSI C does. GDB's answer is more mathematically correct, but the
discrepancy with C can lead to problems when debugging programs.
The following shell transcript illustrates the problem.
$ cat t.c
#include <stdio.h>
float f = 3.40282347e+38;
main() {
printf("%g\n", f + f);
return 0;
}
$ gcc -g t.c
$ gdb a.out
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
(gdb) run
Starting program: /tmp/a.out
Inf
Program exited normally.
(gdb) print f+f
$1 = 6.8056469327705772e+38
gdb should comput f + f == (float) Infinity, like C does, but instead it
computes the result in double precision.
Here is a patch, which relies on the patch that I submitted earlier today
entitled ``GDB 4.7 does not compare `float' to `int' the same way that C
does''. I reported this bug for GDB 4.6, but the fix doesn't seem to have
made its way into GDB 4.7. Perhaps you just haven't gotten around to fixing
this area, but I'm resubmitting this report in case it got lost. The same
patch works for both GDB 4.6 and GDB 4.7.
===================================================================
RCS file: gdb/valarith.c,v
retrieving revision 4.6.1.1
diff -c -r4.6.1.1 gdb/valarith.c
*** gdb/valarith.c 1992/07/15 22:18:24 4.6.1.1
--- gdb/valarith.c 1992/07/15 22:47:55
***************
*** 337,345 ****
return 0; /* For lint -- never reached */
}
! /* Convert two operands to floating point, converting to proper precision. */
! static void
value_floating_operands (arg1, arg2, av1, av2)
value arg1, arg2;
double *av1, *av2;
--- 337,345 ----
return 0; /* For lint -- never reached */
}
! /* Convert two operands to floating point. Yield the result type. */
! static struct type *
value_floating_operands (arg1, arg2, av1, av2)
value arg1, arg2;
double *av1, *av2;
***************
*** 350,357 ****
TYPE_CODE (t1) != TYPE_CODE_FLT ? t2
: TYPE_CODE (t2) != TYPE_CODE_FLT ? t1
: TYPE_LENGTH (t1) < TYPE_LENGTH (t2) ? t2 : t1;
! *av1 = value_as_double (value_from_double (t, value_as_double (arg1)));
! *av2 = value_as_double (value_from_double (t, value_as_double (arg2)));
}
/* Perform a binary operation on two integers or two floats.
--- 350,360 ----
TYPE_CODE (t1) != TYPE_CODE_FLT ? t2
: TYPE_CODE (t2) != TYPE_CODE_FLT ? t1
: TYPE_LENGTH (t1) < TYPE_LENGTH (t2) ? t2 : t1;
!
! *av1 = value_as_double (value_cast (t, arg1));
! *av2 = value_as_double (value_cast (t, arg2));
!
! return t;
}
/* Perform a binary operation on two integers or two floats.
***************
*** 382,388 ****
TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_FLT)
{
double v1, v2, v;
! value_floating_operands (arg1, arg2, &v1, &v2);
switch (op)
{
case BINOP_ADD:
--- 385,391 ----
TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_FLT)
{
double v1, v2, v;
! struct type *t = value_floating_operands (arg1, arg2, &v1, &v2);
switch (op)
{
case BINOP_ADD:
***************
*** 404,413 ****
default:
error ("Integer-only operation on floating point number.");
}
!
! val = allocate_value (builtin_type_double);
! SWAP_TARGET_AND_HOST (&v, sizeof (v));
! *(double *) VALUE_CONTENTS_RAW (val) = v;
}
else
/* Integral operations here. */
--- 407,413 ----
default:
error ("Integer-only operation on floating point number.");
}
! val = value_from_double (t, v);
}
else
/* Integral operations here. */
Technical Details
Message-ID:
<9210251835.AA10380@bi.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!bi.TWinsun.COM!eggertShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,e15c5a7f4507d474,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1992-10-25 12:53:30 PST Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!bi.TWinsun.COM!eggert From: eggert@bi.TWinsun.COM (Paul Eggert) Subject: GDB 4.7 does not add `float' + `float' the same way that C does Message-ID: <9210251835.AA10380@bi.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Sun, 25 Oct 1992 18:35:46 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 124