This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

lrint/lrintf oddity


Hi all,

I've got a little test program below. On Linux, it compiles
using:

    gcc-3.4 -Wall -O3 -std=c99 lrintf_test.c -lm -o lrintf_test

and when run produces:

    lrintf_test ( 3333.000000) : ok
    lrint_test  ( 3333.000000) : ok
    lrintf_test (33333.000000) : ok
    lrint_test  (33333.000000) : ok

On Cygwin using a command line like above i get:

    $ gcc -Wall -O3 -std=c99 lrintf_test.c -o lrintf_test 
    lrintf_test.c: In function `lrintf_test':
    lrintf_test.c:64: warning: implicit declaration of function `lrintf'
    lrintf_test.c: In function `lrint_test':
    lrintf_test.c:88: warning: implicit declaration of function `lrint'

By dropping the -std=c99 it actually compiles, but 
fails the test:

    $ gcc -Wall -O3 lrintf_test.c -o lrintf_test
    $ ./lrintf_test.exe 
    lrintf_test ( 3333.000000) : ok
    lrint_test  ( 3333.000000) : ok
    lrintf_test (33333.000000) : 

    Line 70: float : Incorrect sample (#252 : -8399916.000000 => 889181140).

The gcc version is as follows:

    $ gcc -v
    Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
    Configured with: /gcc/gcc-3.4.4/gcc-3.4.4-1/configure --verbose 
      --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib 
      --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info 
      --enable-languages=c,ada,c++,d,f77,java,objc --enable-nls 
      --without-included-gettext --enable-version-specific-runtime-libs 
      --without-x --enable-libgcj --disable-java-awt --with-system-zlib 
      --enable-interpreter --disable-libgcj-debug --enable-threads=posix 
      --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions 
      --enable-hash-synchronization --enable-libstdcxx-debug : (reconfigured) 
    Thread model: posix
    gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

Anyone know whats going on here? Is this a bug?

Cheers,
Erik

#include <stdio.h>
#include <stdlib.h>

#include <math.h>

#define    BUFFER_SIZE        (1024)

static void    lrintf_test (float fval) ;
static void    lrint_test (double dval) ;

int
main (void)
{
    lrintf_test (3333.0) ;
    lrint_test (3333.0) ;

    lrintf_test (33333.0) ;
    lrint_test (33333.0) ;

    return 0 ;
} /* main */

/*============================================================================================
**    Here are the test functions.
*/

static void
lrintf_test (float fval)
{    int k ;
    float    float_data [BUFFER_SIZE] ;
    int    int_data [BUFFER_SIZE] ;

    printf ("lrintf_test (%12.6f) : ", fval) ;
    fflush (stdout) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        float_data [k] = (k * ((k % 2) ? fval : -fval)) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        int_data [k] = lrintf (float_data [k]) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        if (fabs (int_data [k] - float_data [k]) > 1.0)
        {    printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n",
             __LINE__, k, float_data [k], int_data [k]) ;
            exit (1) ;
            } ;

    printf ("ok\n") ;
} /* lrintf_test */

static void
lrint_test (double dval)
{    int k ;
    double    double_data [BUFFER_SIZE] ;
    int    int_data [BUFFER_SIZE] ;

    printf ("lrint_test  (%12.6f) : ", dval) ;
    fflush (stdout) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        double_data [k] = (k * ((k % 2) ? dval : -dval)) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        int_data [k] = lrint (double_data [k]) ;

    for (k = 0 ; k < BUFFER_SIZE ; k++)
        if (fabs (int_data [k] - double_data [k]) > 1.0)
        {    printf ("\n\nLine %d: double : Incorrect sample (#%d : %f => %d).\n", 
                    __LINE__, k, double_data [k], int_data [k]) ;
            exit (1) ;
            } ;

    printf ("ok\n") ;
} /* lrint_test */




-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"This is like creating laws against blasphemy and then complaining that
unbelievers can't come up with any logical argument against the existence
of God"  -- www.infoanarchy.org on the Digital Millenium Copyright Act
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
A Microsoft Certified System Engineer is to computing what a
MacDonalds Certified Food Specialist is to fine cuisine.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]