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
5
votes
4 answers

How does this sqrt approximation inline assembly function work?

Reading through The Tricks of the 3D Game Programming Gurus, I came across this sort function written in inline assembly: inline float FastSqrt(float Value) { float Result; _asm { mov eax, Value sub eax, 0x3F800000 …
vexe
  • 5,433
  • 12
  • 52
  • 81
5
votes
3 answers

Algorithm to find the largest square number smaller than n

How can I find the largest square number (ie 4, 9, 16) smaller than a given int n efficiently? I have the following attempt: int square = (int)Math.sqrt(number); return square*square; But it has the obvious inefficiency of getting a square root…
David says Reinstate Monica
  • 19,209
  • 22
  • 79
  • 122
5
votes
5 answers

square root algorithm C++

I can not figure out why this algorithm enters an infinite loop if the number entered is over 12 digits. Can anyone see why it will never end? Thanks. I just updated the algorithm to use the fabs() function and still get an infinite loop. double…
csciXAV_12
  • 309
  • 1
  • 5
  • 13
5
votes
2 answers

Search string for numbers

I have a javascript chat bot where a person can type into an input box any question they like and hope to get an accurate answer. I can do this but I know I'm going about this all wrong because I don't know what position the number will appear in…
mister movie
  • 103
  • 1
  • 10
4
votes
3 answers

Finding square root as float from int and remainder?

I'm looking right now at particular algorithm for calculating square root which returns the integer part of the square root and the remainder. So for example: mysqrt(140) = 11*11 + 19 = integer 11, remainder 19 The question is can I calculate the…
4
votes
4 answers

How to include Square root sign as depicted in the following image in android?

I need to include the following square root sign in my android as a Text resource in Button control. Any guesses?
YuDroid
  • 1,599
  • 5
  • 22
  • 44
4
votes
3 answers

Is there a non-looping unsigned 32-bit integer square root function C

I have seen floating point bit hacks to produce the square root as seen here fast floating point square root, but this method works for floats. Is there a similar method for finding the integer square root without loops of a 32-bit unsigned integer?…
yosmo78
  • 489
  • 4
  • 13
4
votes
1 answer

Using Heron's formula to calculate square root in C

I have implemented this function: double heron(double a) { double x = (a + 1) / 2; while (x * x - a > 0.000001) { x = 0.5 * (x + a / x); } return x; } This function is working as intended, however I would wish to improve it.…
Compil3
  • 137
  • 4
  • 13
4
votes
1 answer

How to take the square root of quad_form output in CVXPY?

I am trying to solve a problem that involves \sqrt{w^t \Sigma w} in the objective function. To compute w^t \Sigma w, I use the quad_form function. How do I take its square root? When in the code I try to write risk = sqrt(quad_form(w, E)) I am…
4
votes
2 answers

Arbitrary Precision Arithmetic in Julia

This has kinda been asked, but not in this way. I have a little Python program which finds continued fractions for square roots of n (1 <= n <= 10000). I have been trying to do this in Julia and I can't see how to. Mainly because it deals with…
4
votes
2 answers

Best way to calculate the square root of any number in ios , Objective C and Swift

I am asking for ways to calculate the square root of any given number in ios, Objective C. I have inserted my way to do it using log. the logic was. ex : find the square root of 5 X = √5 then log10X = log10(√5) this means log10X =…
caldera.sac
  • 4,918
  • 7
  • 37
  • 69
4
votes
3 answers

Fortran computes square root of real*4 as fast as addition of ints?

Spoiler: The test program did nothing with the results, so the contents of the loops were removed by the optimizing compiler and thus looping over nothing takes about the same time each run... Anyway, i'll let the question and answers remain in case…
Jonatan Öström
  • 2,428
  • 1
  • 16
  • 27
4
votes
9 answers

Estimating the square root

I am writing an iPhone app that needs to calculate the square root of a number about 2000 times every 1/30th of a second. sqrt() works fine on a computer, but the frame rate drops to around 10 FPS on an iPhone or iPad, and I have already optimized…
Chris
  • 1,037
  • 15
  • 26
4
votes
3 answers

square numbers Java

"An array is used to store ten integer numbers. Write a Java program that determines and print the square numbers which are also odd numbers from the given array." The problem I have is how to figure out if the number in the array is a square…
laish138
  • 243
  • 1
  • 2
  • 10
4
votes
2 answers

Calculating nth root of a positive integer in Java

My task is to write a program which prompts the user to enter a positive double a and an integer n greater than 2, and print the value of the nth root of positive integer a to the screen with accuracy to 100 places. I've used Math.pow to be able to…
Ibrewster
  • 187
  • 5
  • 18