www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/06/12:07:32

From: Mark Cowan <mark DOT cowan AT studentmail DOT newcastle DOT edu DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP BUG!!!!!!! ???
Date: Thu, 06 Jan 2000 21:17:52 -0800
Organization: The University of Newcastle
Lines: 83
Message-ID: <387576FF.6902831B@studentmail.newcastle.edu.au>
References: <851o9m$h4t$1 AT news DOT lth DOT se> <38757518 DOT CEE78971 AT studentmail DOT newcastle DOT edu DOT au>
NNTP-Posting-Host: c53h3-asy92.newcastle.edu.au
Mime-Version: 1.0
X-Mailer: Mozilla 4.7 [en] (Win98; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

You probably have already thought of this but here is a work around anyway

#include <iostream>

int main()                                                                   {
        for ( double i = 1.0; i < 3.1; i += 0.1 )
        {
                cout << "Double:" << (i - 1.0) << ", Integer:" << ((int) i - 1)
<< endl;
        }
        return (0);                                                          }

Mark

--
_____________________________________________

Mark Cowan
Newcastle Australia

Mark Cowan wrote:

> I normally do casts in this way
> (int) double_val
>
> However after doing this with your code I got the same results as you.
>
> Then I did a test
>
> double one = 1.0;
> cout << "Test: " << (int) one << endl;
>
> gave me
> Test: 1
>
> weird.
>
> Mark
> --
> _____________________________________________
>
> Mark Cowan
> Newcastle Australia
>
> Niklas Pettersson wrote:
>
> > Hello!
> >
> > I think I have found an error in DJGPP... It's illustrated by the following
> > example:
> >
> > #include <iostream>
> >
> > int main()
> > {
> >  for ( double i = 0; i < 2.1; i += 0.1 )
> >    {
> >     cout << "Double:" << i << ", Integer:" << int(i) << endl;
> >    }
> >
> >    return (0);
> > }
> >
> > You should expect it to print
> >
> > 0.1   0
> > ..
> > ..
> > 0.9   0
> > 1.0   1
> > ...
> >
> > but 1.0 gets converted to 0!!!!
> > and even worse, 2.0 gets converted to 2... strange.. not a general
> > behaviour...
> >
> > Is this a bug or is it me that are to dumb? (I have coded almost the whole
> > night)...
> >
> > Any comments are appreciated
> >
> > / Niklas

- Raw text -


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