Article View: gnu.gdb.bug
Article #8885float+float yields double; should yield float
From: Paul Eggert
Date: Wed, 15 Jul 1992 22:53
Date: Wed, 15 Jul 1992 22:53
121 lines
4296 bytes
4296 bytes
[I reported this bug earlier for GDB 4.5; this bug report includes an improved
patch.]
GDB 4.6 (SunOS 4.1.2, sparc) computes a double-precision number whenever it
adds two single-precision numbers; but it should compute a single-precision
number, because that's what C does. 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.6, Copyright 1992 Free Software Foundation, Inc...
(gdb) print f + f
$1 = 6.8056469327705772e+38
(gdb) run
Starting program: /tmp/a.out
Inf
Program exited normally.
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 does not compare `float' to `int' correctly''.
===================================================================
RCS file: valarith.c,v
retrieving revision 4.6.1.1
diff -c -r4.6.1.1 valarith.c
*** valarith.c 1992/07/15 22:18:24 4.6.1.1
--- 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:
<9207152253.AA20882@farside.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggertShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,abb2ce2f6e8ba7e2,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1992-07-15 17:04:00 PST Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert From: eggert@twinsun.COM (Paul Eggert) Subject: float+float yields double; should yield float Message-ID: <9207152253.AA20882@farside.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Wed, 15 Jul 1992 22:53:37 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 122