Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Jeff Taylor <jeff@Adeno.wistar.upenn.edu>
Subject: GCC bug???
Date: Fri, 15 Mar 1996 15:47:42 -0500 (EST)	[thread overview]
Message-ID: <a494f9259de31e6d130cf25dbb7e6fb7.axp-list@archive.invalid> (raw)

Hello Alpha users -

	I'm not sure if this qualifies as a bug in the technical sense, but
it seems at least to be an inconsistany between Alpha Linux/GCC and
x86 Linux/GCC.  I ran into this problem with the math lib function pow(), but 
it may occur elsewhere.  It occurs when incorrectly typed variables 
(ints, or longs) are passed to the pow() function, which as I understand, 
expects doubles.  I compiled the following code with GCC on a Linux/Pentium 
system and it works fine:

#include <stdlib.h>
#include <math.h>

main()
{
    int i;
    int x;
    for (i=0;i<6;i++)
    {
     x=pow(2,i);
       printf("%d   %ld\n",i,x);
    }
}
Output is:
0   1
1   2
2   4
3   8
4  16
5  32

The same code compiled on Linux/Alpha gives :
#include <stdlib.h>
#include <math.h>

main()
{
    int i;
    int x;
    for (i=0;i<6;i++)
    {
     x=pow(2,i);
       printf("%d   %ld\n",i,x);
    }
}
Output :
0   1
1   2
2   4
3   7
4   15
5   32

It seems to be something strange in the conversion from one type to another.
For example : 
 main()
 {
     int i;
     double x,y;
     for (i=0;i<21;i++)
     {
        x= pow(2.0,i);
        y = (int)x;
        printf("%d   %g %g\n",i,x,y);
     }
 }

Gives Output:
0   1   1
1   2   2
2   4   4
3   8   7
4   16   15
5   32   32

There are no warnings of potential problems at compile time and because
this problem does not occur with the x86 GCC (I haven't tried any other
platforms).  Being a C beginner, I'm not sure what should happen, but I think
at least a warning is warrented.

Jeff Taylor

             reply	other threads:[~1996-03-15 20:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-15 20:47 Jeff Taylor [this message]
     [not found] <199603152047.PAA02208@Adeno.wistar.upenn.edu>
1996-03-15 22:54 ` GCC bug??? yxc02740
  -- strict thread matches above, loose matches on Subject: below --
1996-03-15 23:52 David Mosberger-Tang
1997-04-05 16:22 gcc bug? Michael Alan Dorman
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox