From: jdeifik@weasel.com (Jeff Deifik)
Subject: beta 18 'rint' function with gcc is broken
12 May 1997 01:42:24 -0700
Approved: cygnus.gnu-win32@cygnus.com
Distribution: cygnus
Message-ID: <3.0.32.19970511224439.010096f0.cygnus.gnu-win32@pop.ni.net>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=====================_863441088==_"
X-Sender: jdeifik@pop.ni.net
X-Mailer: Windows Eudora Pro Version 3.0 (32)
Original-To: gnu-win32@cygnus.com
Original-Sender: owner-gnu-win32@cygnus.com

--=====================_863441088==_
Content-Type: text/plain; charset="us-ascii"

I am running windows nt 4.0 server, sp2.
I have a library regression test that I run on the compilers I use.
It showed a bug with the 'rint' function.
This function is supposed to convert a double to an integral double
value. It isn't working, as the enclosed test program shows.

Compile with no options, i.e.
gcc yy.c
yy

The output should be nothing, but it is:
47.4 47.125000
47.6 47.625000
-47.4 -47.125000
-47.6 -47.625000

	Jeff Deifik
--=====================_863441088==_
Content-Type: text/plain; charset="us-ascii"

/* y.c, demonstrates a bug with gnu-w32 beta 18 */
/* Written 11/06/96 by Jeff Deifik	*/
/* Modified 05/11/97 by Jeff Deifik	*/

#include	<stdio.h>
#include	<math.h>

typedef enum { False = 0, True = 1 } Boolean;

float FLOAT_TO_ROUNDED_FLOAT(float);
int flo_close(double value,double f,double clo);

int main(int argc, char *argv[])
{
Boolean	fail = False;
double	d;
float	f;

    d = rint(47);
    if (!flo_close(47.0f,d,0.0001f))
      { (void)printf("47 %f\n",d); fail = True; }

    f = FLOAT_TO_ROUNDED_FLOAT(47.0);
    if (!flo_close(47.0f,f,0.0001f))
      { (void)printf("47 %f\n",f); fail = True; }

    d = rint(47.4);
    if (!flo_close(47.0f,d,0.0001f)) { (void)printf("47.4 %f\n",d); fail = True; }
    d = rint(47.6);
    if (!flo_close(48.0f,d,0.0001f)) { (void)printf("47.6 %f\n",d); fail = True; }
    d = rint(-47);
    if (!flo_close(-47.0f,d,0.0001f)) { (void)printf("-47 %f\n",d); fail = True; }
    d = rint(-47.4);
    if (!flo_close(-47.0f,d,0.0001f)) { (void)printf("-47.4 %f\n",d); fail = True; }
    d = rint(-47.6);
    if (!flo_close(-48.0f,d,0.0001f)) { (void)printf("-47.6 %f\n",d); fail = True; }

    return 0;
}


/* Value is the ideal number, f is what it really is.*/
int	flo_close(double value,double f,double clo)
{
    return(((f+clo) >= value) && ((f-clo) <= value));
}

float	FLOAT_TO_ROUNDED_FLOAT(float x)		{ return(floor(x+0.5)); }


--=====================_863441088==_--

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
