2

Lets consider the following example. double x = 1234597000.0

When i save the value of x in DB, it is stored as 1234600000. When i do subtraction operation in program, it is getting treated as 1234600000. Would you please help me to understand what is going on there?

my system is solaris and compiling the program using Sun Studio C++(CC) compiler.

Thanks in advance.

1
  • "When i save the value of x in DB"? What DB? Commented Apr 18, 2011 at 22:38

2 Answers 2

6

You're hitting the pitfalls of the IEEE floating-point encoding. This questions comes up quite a bit. Please see What Every Computer Scientist Should Know About Floating-Point Arithmetic

Sign up to request clarification or add additional context in comments.

Comments

2

It looks like your double is getting converted to or from a float (read: losing precision) somewhere along the line. Floats only have about 6-7 significant digits IIRC, as opposed to over a dozen for doubles.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.