Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: [Off Topic] Rounding errors

Author: Alessandro Scotti

Date: 17:36:05 11/25/04

Go up one level in this thread


On November 25, 2004 at 20:17:15, macaroni wrote:

>If I have a piece of c++ code like:
>
>double x = 2000;
>double y = 2.000002;
>cout << x-y << "\n";
>
>will display 1998. Is there a way I can avoid this rounding problem?
>any help much appreciated.

It's not a rounding error. Add this to your code:

cout.setf( std::ios_base::scientific );



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.