bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Float problems with trunc() and round()


From: Kjeld Borch Egevang
Subject: Re: Float problems with trunc() and round()
Date: Wed, 3 Oct 2001 23:11:27 +0200 (CEST)

Andreas is right. The test was broken. I wasn't able to find any .h-files
containing trunc() and round() (that seems to be the real problem).

But it works with:

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

extern float truncf(float x);
extern float roundf(float x);

int main()
{
    float x;

    x = 3.0/2;
    printf("%e %e %e %e %e\n", x, floor(x), ceil(x), truncf(x),
roundf(x));
    return 0;
}

printing out:

1.500000e+00 1.000000e+00 2.000000e+00 1.000000e+00 2.000000e+00


Thanks for your comments.

/Kjeld


On 3 Oct 2001, Andreas Schwab wrote:

> Justin Guyett <address@hidden> writes:
>
> |> On 3 Oct 2001, Andreas Schwab wrote:
> |>
> |> > Kjeld Borch Egevang <address@hidden> writes:
> |> >
> |> >> I suppose the functions trunc() and round() should do something
> |> >> similar to ceil() and floor(). When I try this on my i686-linux, it
> |> >> seems to be broken. Here is my test:
> |> >
> |> > Your test is broken.
> |>
> |> (glibc 2.2.4, i686-pc-linux-gnu, 2.4.9-ac3, gcc 2.95.3)
> |>
> |> ---CUT---
> |> #include <stdio.h>
> |> #include <math.h>
> |>
> |> int main(int argc, char **argv)
> |> {
> |>    printf("%f %f\n", truncf(1000.250), roundf(1000.501));
> |>    return(0);
> |> }
> |> ---CUT---
> |>
> |> % gcc -o t1 -lm test.c
> |> % ./t1
> |> 0.000000 2.086854
> |>
> |>
> |> looks broken to me, but maybe i'm forgetting something
>
> Yes, the test is *still* broken.  Learn to use -Wall.
>
> gcc -O2 -g -Wall     round.c  -lm -o round
> round.c: In function `main':
> round.c:6: warning: implicit declaration of function `truncf'
> round.c:6: warning: implicit declaration of function `roundf'
> round.c:6: warning: double format, different type arg (arg 2)
> round.c:6: warning: double format, different type arg (arg 3)
>
> Andreas.
>
>

-- 
_    _ ____  ___                       Mailto:address@hidden
|\  /|||___)(___    MIPS Denmark       Direct: +45 44 86 55 85
| \/ |||    ____)   Lautrupvang 4 B    Switch: +45 44 86 55 55
  TECHNOLOGIES      DK-2750 Ballerup   Fax...: +45 44 86 55 56
                    Denmark            http://www.mips.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]