Search:
Forum
General C++ Programming
Detect precision loss
Detect precision loss
Sep 5, 2010 at 4:54pm UTC
Asteroth
(5)
Hello.
Is there any way to detect if there would be precission loss when converting a double to float without manually process the variable bits?
Somethink like:
double a = 123.456;
double b = 12345.6789;
std::cout <<precisionLoss(a) <<"\n";
std::cout <<precisionLoss(b) <<"\n";
should print:
0
1
Thanks in advance.
Sep 5, 2010 at 5:54pm UTC
Asteroth
(5)
Nevermind, I've investigated a little and found that:
1.2 != (double)((float)1.2)
and I think that means that the precision loss is very probable even for numbers with few digits.
Sep 5, 2010 at 6:13pm UTC
Disch
(13742)
Precision loss is probable for numbers with only 1 digit. Even without converting between types. 1.0 does not necessarily equal 1.0.
Read this:
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.16
Last edited on
Sep 5, 2010 at 6:13pm UTC
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs