Shortest way to check perfect Square? [duplicate]

Probably checking if the square root of the number has any decimal part, or if it is a whole number. Implementationwise, I would consider something like this: double result = Math.Sqrt(numberToCheck); bool isSquare = result%1 == 0; isSquare should now be true for all squares, and false for all others.

How does the computer calculate Square roots? [closed]

Most modern non-embedded CPUs (x86 and the larger ARM cores, for example) have hardware instructions to compute square roots directly. The hardware implementation backing these instructions varies, but typically is a variant on the schoolbook digit-by-digit algorithm (though not always in base two; base four or sixteen can also be used). These are typically among … Read more

Looking for an efficient integer square root algorithm for ARM Thumb2

Integer Square Roots by Jack W. Crenshaw could be useful as another reference. The C Snippets Archive also has an integer square root implementation. This one goes beyond just the integer result, and calculates extra fractional (fixed-point) bits of the answer. (Update: unfortunately, the C snippets archive is now defunct. The link points to the … Read more

Square root of BigDecimal in Java

I’ve used this and it works quite well. Here’s an example of how the algorithm works at a high level. Edit: I was curious to see just how accurate this was as defined below. Here is the sqrt(2) from an official source: (first 200 digits) 1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147 and here it is using the approach I outline … Read more

John Carmack’s Unusual Fast Inverse Square Root (Quake III)

FYI. Carmack didn’t write it. Terje Mathisen and Gary Tarolli both take partial (and very modest) credit for it, as well as crediting some other sources. How the mythical constant was derived is something of a mystery. To quote Gary Tarolli: Which actually is doing a floating point computation in integer – it took a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)