Re: gcc strangeness

From: Cyrille Lefevre (clefevre-lists_at_9online.fr)
Date: 07/12/04

  • Next message: Steven Smith: "Re: Article on Sun's DTrace"
    To: "Roman Kurakin" <rik@cronyx.ru>, "Dmitry Morozovsky" <marck@rinet.ru>
    Date: Mon, 12 Jul 2004 15:30:45 +0200
    
    

    "Roman Kurakin" <rik@cronyx.ru> wrote:
    > Dmitry Morozovsky wrote:
    [snip]
    > >marck@woozle:/tmp/tsostik> cat x.c
    > >#include <stdio.h>
    > >int main ()
    > >{
    > > float a;
    > > for(a=0.01;a<=0.1; a+=0.01)
    > > printf("%f %.3f %d\n", a*100, a*100, (int)(a*100));
    > >
    > >
    > I believe this should more correct:
    > printf ("%f %.3f %d\n", a*100, a*100, (int)(a*100+.5));

    it is much better to use ceilf(3) (or ceil(3) for double) here :

    printf("%f %.3f %f %d\n", a*100, a*100,
                            ceilf(a*100), (int)ceilf(a*100));

    # ./a.out
    1.000000 1.000 1.000000 1
    2.000000 2.000 2.000000 2
    3.000000 3.000 3.000000 3
    4.000000 4.000 4.000000 4
    5.000000 5.000 5.000000 5
    6.000000 6.000 6.000000 6
    7.000000 7.000 7.000000 7
    8.000000 8.000 8.000000 8
    9.000000 9.000 9.000000 9
    9.999999 10.000 10.000000 10

    Cyrille Lefevre.

    -- 
    home: mailto:cyrille.lefevre@laposte.net
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: Steven Smith: "Re: Article on Sun's DTrace"

    Relevant Pages

    • Re: req: New feature to rm? Remove file by the inode number
      ... >> To unsubscribe, send any mail to ... > Take Yahoo! ... UNIX systems consultant ...
      (freebsd-hackers)
    • Re: SoundCard Problem - soundcard working now
      ... then i installed alsa: apt-get install alsa ... To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org ... If you have received this email in error please notify the ...
      (Debian-User)
    • Re: OT
      ... whether we should just expect people to use filters and 'ignore ... when criticizing them. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: What is this kernel error?
      ... Nothing in the exim4 logs. ... active was a python script doing an nntp download but I've been running ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: How to reclaim space on hard drive not partitioned fully initially?
      ... Thank you very much for your extraordinarily clear explanation of what was going on and plan for proceeding. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
      (Debian-User)