Ticket #3368: maths.patch
File maths.patch, 1.5 KB (added by , 9 years ago) |
---|
-
Sqrt.cpp
19 19 20 20 #include "Sqrt.h" 21 21 22 #if !(defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__)) 23 24 // NOTE: this handwritten sqrt function has been found to be much slower than the 25 // one provided by the standard library on the MSVC, GCC and Clang compilers on 26 // x86 and x86-64 architectures. Other compilers and architectures have not been 27 // tested but the performance penalty is likely to be comparable. 28 22 29 // Based on http://freaknet.org/martin/tape/gos/misc/personal/msc/sqrt/sqrt.html 23 30 u32 isqrt64(u64 n) 24 31 { … … 42 49 return (u32)res; 43 50 } 44 51 45 // TODO: This should be equivalent to (u32)sqrt((double)n), and in practice 46 // that seems to be true for all input, so do we actually need this integer-only 47 // implementation? i.e. are there any platforms / compiler settings where 48 // sqrt(double) won't give the correct answer? and is sqrt(double) faster? 52 #endif -
Sqrt.h
22 22 * 64-bit integer square root. 23 23 * Returns r such that r^2 <= n < (r+1)^2, for the complete u64 range. 24 24 */ 25 //NOTE: see Sqrt.cpp note 26 #if defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__) 27 28 #include <cmath> 29 inline u32 isqrt64(u64 n) { return (u32)sqrt((double)n); } 30 31 #else 32 25 33 u32 isqrt64(u64 n); 26 34 35 #endif 36 27 37 #endif // INCLUDED_MATH_SQRT