Click on image to see enlargment
In computing the square root of 2 by a variant of Newton's method the programmer was shocked to find that the answer printed was 1.5 -- what's the mistake?
bug524.cpp lint Output
--- Module: bug524.cpp _ while( abs( error = y - x * x ) > .0005 ) bug524.cpp(10) : Warning 524: Loss of precision (assignment) (double to int) bug524.cpp(10) : Info 747: Significant prototype coercion (arg. no. 1) int to double _ printf( "sqrt(%d) = %8.3f\n", 2, sqrt(2) ); bug524.cpp(17) : Info 747: Significant prototype coercion (arg. no. 1) int to double
Reference Manual Explanation
524 Loss of precision (Context) (Type to Type) -- There is a possible loss of a fraction in converting from a float to an integral quantity. Use of a cast will suppress this message.
If you have comments or questions about this bug, please post them to our Discussion Forum
Previous Bug - Bug #437 - December 2003