I think the answer is no due to floating point inaccuracy, but you can always add some small value to the result before casting to the integer type to avoid truncating to less than the integer square root.Originally Posted by megafiddle
I think the answer is no due to floating point inaccuracy, but you can always add some small value to the result before casting to the integer type to avoid truncating to less than the integer square root.Originally Posted by megafiddle
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The answer is no due to floating point inaccuracy (and the fact that floating point variables can't represent as many integral values as an integral type of the same or larger size).
It's generally not a good idea to use sqrt() when working with integers, anyway. There are plenty of algorithms around for computing the integer square root (the largest integer which, when multiplied by itself, does not exceed the value).