How can I come to know that the system has done a rounding during a calculation or not?
I mean for example 4/2=2 is an exact calculation of doubles because 4 and 2 are represented exactly. But for example 4/3 is not an exact calculation. I would like to know that my result is exact or not! It is possible somehow?
merse
0
Junior Poster
Recommended Answers
Jump to PostI would like to know that my result is exact or not! It is possible somehow?
See: http://docs.sun.com/source/806-3568/ncg_goldberg.html
Perhaps you should consider using a library; for example MPFR
Jump to PostHow do you think 4/2 is represented in memory? If you use doubles it will be 2.0000... Similarily 4/3 is 1.3333... in memory. Its NOT just a string -- that is the binary representation.
If you want to know how doubles are formatted in memory then you need to …
Jump to PostIf your computer supports IEEE floating-point, as most processors do, the five fundamental operations + - * / and sqrt will yield the correctly rounded result.
Jump to PostIf you have an IEEE-compliant implementation, then rounding is according to the current rounding mode, which by default is to round to the nearest value and to round to even in case of ties.
If you set the rounding mode differently (and standard C++ does not offer a standardized …
Jump to PostI remembered answering a similar post before here, but then I realized you (merse) were also the OP for that thread. I guess you are obsessed with this topic... If what your are looking for is top speed and perfect accuracy, you just moved beyond obsession.. into fanatical idealism. …
All 18 Replies
group256
-3
Junior Poster
vijayan121
1,152
Posting Virtuoso
merse
0
Junior Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
jonsca
commented:
yep
+5
merse
0
Junior Poster
arkoenig
340
Practically a Master Poster
merse
0
Junior Poster
arkoenig
340
Practically a Master Poster
arkoenig
340
Practically a Master Poster
merse
0
Junior Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
merse
0
Junior Poster
merse
0
Junior Poster
group256
-3
Junior Poster
arkoenig
340
Practically a Master Poster
arkoenig
340
Practically a Master Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
merse
0
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.