Article View: fr.comp.lang.c
Article #15413Re: virgule flottante et FLT_EPSILON
From: Yves ROMAN
Date: Tue, 27 Sep 2005 07:38
Date: Tue, 27 Sep 2005 07:38
33 lines
2068 bytes
2068 bytes
"Tribulations Parall�les" <Noparatribulations@freeee_._frspaM> a �crit dans
le message de news: 43386482$0$26880$626a14ce@news.free.fr...
> Bonjour � tous,
>
> En effet, en essayant le petit programme ci-dessous, on se rend compte que
> x=15, y=14. Afin de r�ellement obtenir 15, je rajoute FLT_EPSILON au
> num�rateur dans y.
> J'ai deux questions:
> 1- x et y me semblent identiques au premier abord. Que se passe-t-il de
> diff�rent dans ces deux cas? Pourquoi passer par des noms de variable
> semble changer la donne?
[...]
>
> #include <stdio.h>
> #include <float.h>
>
> int main(void)
> {
> float t2=1.5, t1=0.0, h=0.1;
> int x=(1.5-0.0)/0.1;
Certains compilateurs peuvent calculer directement la valeur de x � la
compilation (comme MSVC)
D'autre vont g�n�rer du code pour le calculer � l'ex�cution, mais
probablement en double et non en float (comme Sparc Compiler)
> int y=(t2-t1)/h;
> int y_corrected=(t2-t1+FLT_EPSILON)/h;
> printf("x=%i, y=%i, y_corrected=%i\n",x,y,y_corrected);
>
> return 0;
> }
>
Technical Details
Message-ID:
<dhasrb$bg7$1@s1.news.oleane.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!134.158.69.22.MISMATCH!in2p3.fr!oleane.net!oleane!not-for-mailReferences:
<43386482$0$26880$626a14ce@news.free.fr>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,309c5052b3bcc1bf X-Google-Attributes: gidf9822,public X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!134.158.69.22.MISMATCH!in2p3.fr!oleane.net!oleane!not-for-mail From: "Yves ROMAN" <yves.roman@NO.unilog.SPAM.fr> Newsgroups: fr.comp.lang.c Subject: Re: virgule flottante et FLT_EPSILON Date: Tue, 27 Sep 2005 09:38:48 +0200 Organization: Guest of France Telecom's news reading service Lines: 35 Message-ID: <dhasrb$bg7$1@s1.news.oleane.net> References: <43386482$0$26880$626a14ce@news.free.fr> NNTP-Posting-Host: cerbere.unilog.fr X-Trace: s1.news.oleane.net 1127806635 11783 194.3.185.2 (27 Sep 2005 07:37:15 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Tue, 27 Sep 2005 07:37:15 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original