ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/10/06:46:41

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <3CB40560.DB601EE6@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Organization: Nocturnal Aviation
X-Mailer: Mozilla 4.77 [en] (Win95; U)
X-Accept-Language: en,de-CH,fr,ru,zh-CN,ja
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
Subject: Re: Weird double problem?!
References: <142c67c0 DOT 0204092338 DOT 1ce7acb3 AT posting DOT google DOT com>
Lines: 73
Date: Wed, 10 Apr 2002 09:26:59 GMT
NNTP-Posting-Host: 63.210.219.138
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread1.prod.itd.earthlink.net 1018430819 63.210.219.138 (Wed, 10 Apr 2002 02:26:59 PDT)
NNTP-Posting-Date: Wed, 10 Apr 2002 02:26:59 PDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Taras wrote:
> 
> Hi everyone,
> 
> Just doing some basic programming for maths, and something really
> weird happened.  I'm using RHIDE 1.4.9 w/ djgpp 2.03.  I have this
> line in my
> program:
> 
>   const double stepSize;
>   stepSize = 0.1;
> 
> when i step through the program and watch the variable step size, when
> it
[ .. the usual question ]

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

int main(void)
{
    double x = 0.1;
    double value = 0, den = 1;
    size_t i;
    double ipart, num = 0;
    for (i = 0; i <= DBL_MANT_DIG; i++, den *= 2, x *= 2, num *= 2) {
        x = modf(x, &ipart);
        if (ipart) {
            num++;
            value += ipart / den;
            printf("+ %g/%.0f = %.0f/%.0f = %.*g\n", ipart, den, num,
                   den, DBL_DIG, value);
        }
    }
    return 0;
}



+ 1/16 = 1/16 = 0.0625
+ 1/32 = 3/32 = 0.09375
+ 1/256 = 25/256 = 0.09765625
+ 1/512 = 51/512 = 0.099609375
+ 1/4096 = 409/4096 = 0.099853515625
+ 1/8192 = 819/8192 = 0.0999755859375
+ 1/65536 = 6553/65536 = 0.0999908447265625
+ 1/131072 = 13107/131072 = 0.0999984741210938
+ 1/1048576 = 104857/1048576 = 0.0999994277954102
+ 1/2097152 = 209715/2097152 = 0.0999999046325684
+ 1/16777216 = 1677721/16777216 = 0.0999999642372131
+ 1/33554432 = 3355443/33554432 = 0.0999999940395355
+ 1/268435456 = 26843545/268435456 = 0.0999999977648258
+ 1/536870912 = 53687091/536870912 = 0.099999999627471
+ 1/4294967296 = 429496729/4294967296 = 0.0999999998603016
+ 1/8589934592 = 858993459/8589934592 = 0.0999999999767169
+ 1/68719476736 = 6871947673/68719476736 = 0.0999999999912689
+ 1/137438953472 = 13743895347/137438953472 = 0.0999999999985448
+ 1/1099511627776 = 109951162777/1099511627776 = 0.0999999999994543
+ 1/2199023255552 = 219902325555/2199023255552 = 0.0999999999999091
+ 1/17592186044416 = 1759218604441/17592186044416 = 0.0999999999999659
+ 1/35184372088832 = 3518437208883/35184372088832 = 0.0999999999999943
+ 1/281474976710656 = 28147497671065/281474976710656 =
0.0999999999999979
+ 1/562949953421312 = 56294995342131/562949953421312 =
0.0999999999999996
+ 1/4503599627370496 = 450359962737049/4503599627370496 =
0.0999999999999999
+ 1/9007199254740992 = 900719925474099/9007199254740992 = 0.1

-- 
It is better to be wrong than vacuous.
  - Avram Noam Chomsky

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019