Questions tagged [square-root]

A square root of a number A is a number y such that y^2 = A, or, in other words, a number y whose square (the result of multiplying the number by itself, or y × y) is A.

A square root of a number A is a number y such that y2 = a, or, in other words, a number y whose square (the result of multiplying the number by itself, or y × y) is A.

398 questions
8
votes
3 answers

Simplify square roots algebraically

I would like to simplify the square root of an integer algebraically, not compute it numerically, i.e. √800 should be 20√2 , not 28.2842712474619. I cannot find any way to solve this through programming :(
Sourav
  • 17,065
  • 35
  • 101
  • 159
7
votes
5 answers

Nth root of BigInteger

I'm using a BigInteger object. With normal ints or longs, I can use Math.pow(number, 1/nth root) to get the nth root. However, this will not work with a BigInteger. Is there a way I can do this? I do not actually need the root, just to know if it…
James McDowell
  • 2,668
  • 1
  • 14
  • 27
7
votes
2 answers

perfect square algorithm - explanation for the implementation

This question is a follow-up on the post here: Fastest way to determine if an integer's square root is an integer, What's a good algorithm to determine if an input is a perfect square?. One of the posts there had this solution to find if a given…
brain storm
  • 30,124
  • 69
  • 225
  • 393
7
votes
2 answers

Square root function in Forth using x86 Assembly?

I don't know much about assembly, but I am pretty sure that there are square root instructions on the x86? I am trying to get a square root function to work well in froth and the one that I have found gets bogged down somehow when I run it many…
Will
  • 233
  • 3
  • 11
7
votes
3 answers

How to properly use "iterate" and "partial" in Clojure?

Most reference to iterate are for operators, and all the applications on functions are so confusing that I still don't get how to use iterate in my code, and what partial is. I am doing a programming homework, trying to use Newton's method to get…
zaolian
  • 1,187
  • 3
  • 11
  • 21
7
votes
5 answers

Distance between two points without using the square root

Is it possible to calculate the distance between two points without having to use the math.h library? I know that, using the math.h library, it would have to be something among these lines (Euclidean distance formula): int Distance(int x1, int y1,…
Raphm
  • 105
  • 1
  • 2
  • 6
7
votes
0 answers

square root by bit shift

I am studying the fast square root algorithm by bit shift. I was stuck by the code from wikipedia. short isqrt(short num) { short res = 0; short bit = 1 << 14; // The second-to-top bit is set: 1L<<30 for long // "bit" starts at the…
csrfengye
  • 71
  • 1
  • 1
  • 5
6
votes
2 answers

Infinite Recursion in Meta Integer Square Root

Good day, A friend of mine is asking about transforming an integer square root function into a meta-function. Here is the original function: unsigned isqrt(unsigned value) { unsigned sq = 1, dlt = 3; while(sq<=value) { sq +=…
Khaled Alshaya
  • 94,250
  • 39
  • 176
  • 234
6
votes
2 answers

Integer ceil(sqrt(x))

The answer gives the following code for computing floor(sqrt(x)) using just integers. Is it possible to use/modify it to return ceil(sqrt(x)) instead? Alternatively, what is the preferred way to calculate such value? Edit: Thank you all so far and I…
minmax
  • 493
  • 3
  • 10
6
votes
8 answers

JavaScript - Improving algorithm for finding square roots of perfect squares without Math.sqrt

I'm trying to learn algorithms and coding stuff by scratch. I wrote a function that will find square roots of square numbers only, but I need to know how to improve its performance and possibly return square roots of non square numbers function…
user5680735
  • 703
  • 2
  • 7
  • 21
6
votes
2 answers

Fast Integer Square Root

Is there any faster or more direct way of computing the integer square root: http://en.wikipedia.org/wiki/Integer_square_root in C# as private long LongSqrt(long value) { return Convert.ToInt64(Math.Sqrt(value)); } ?
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
6
votes
1 answer

An efficient algorithm to calculate the integer square root (isqrt) of arbitrarily large integers

Notice For a solution in Erlang or C / C++, go to Trial 4 below. Wikipedia Articles Integer square root The definition of "integer square root" could be found here Methods of computing square roots An algorithm that does "bit magic" could be…
6
votes
2 answers

inverse square root in Python

Does any Python library offer a function that implements the "fast inverse square root" algorithm described in following link? http://en.wikipedia.org/wiki/Fast_inverse_square_root Perhaps numpy/SciPy?
Andreas Gschossmann
  • 669
  • 1
  • 6
  • 21
6
votes
2 answers

What is the fastest way to find integer square root using bit shifts?

I was looking for the fastest method to calculate the square root(integer) of a number(integer). I came across this solution in wikipedia which finds the square root of a number(if its a perfect square) or the square root of its nearest lower…
Ritesh Mahato
  • 621
  • 9
  • 15
5
votes
1 answer

Something really weird with C++ exp() function

When tying to implement mySqrt function in C++, I used the exp() function like this: int mySqrt(int x) { // For x = 2147395600 cout << exp(0.5*log(x)) << " "; // It prints 46340 return exp(0.5*log(x)); // But returns…
Rakshak
  • 73
  • 6
1 2
3
26 27