Solved

Double precision and iostream library

Posted on 1997-02-26
1
522 Views
Last Modified: 2008-02-26
Hi,

the following problem:

I have a double precision number,
double x = -9.3456

Then I try to output it using the following commands:
cout.setf(ios::fixed,ios::floatfield);
cout.precision(16);
cout << x;

...and this is the result:

-9.3455999999999992

What I need to know is:

which is the number actualy stored in memory ?
what happens ?

Thanks for any help.

Roberto

0
Comment
Question by:roberto022697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
jordan122196 earned 100 total points
ID: 1162124
The actual number stored in memory is:
-9.3455999999999992

This is the closest number to -9.3456 that can be stored
in the bits of a double.  Numbers are stored in base 2 (one's
and zeros).  Thus you can exactly store the numbers: 8,4,0.5,
0.25, etc. but a number like 0.1 cannot be exactly stored.

In computer science we accept this small error ( called floating
point error ) as a fact of life.

jordan

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 143
VS2015 compilation and missing DLLs 9 190
FMX StringGrid1->Canvas->FillRect Problem 3 218
c++  placing data into a form and an editbox 5 45
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question