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
3
votes
1 answer

Square root using Taylor series

I would like to compute square root using Taylor series. I'm just learning about the series and I wrote a bit of code but I don't know why it doesn't work, maybe I shouldn't feed i to it? Please can anyone explain to me what I'm doing wrong? I have…
Tuom L.
  • 182
  • 3
  • 12
3
votes
1 answer

sqrt function weird behaviour in Python

In Python, I wrote a custom code sqrt(x, delta) to calculate the square root of a given number with a delta-close approximation. It uses a while loop and a binary-search-like algorithm. The code: from __future__ import division def sqrt(x,…
user1563285
2
votes
4 answers

Math.sqrt() returns infinity?

Math.sqrt(); seems to work fine with any number less than 310 characters long. However, any number 310 chars or over will return infinity... If you want to test it out yourself, here it is on jsfiddle http://jsfiddle.net/gqhk9/2 Anyway, I need to…
monkey blot
  • 985
  • 3
  • 10
  • 18
2
votes
3 answers

Precise Square Roots in Java

What is the best way to store irrational numbers like square roots in Java? I need a great deal of precision (over 100 digits), so float and double won't be good. Is it BigDecimal? I was using that before but I ran into strange problems, it could…
user1126849
  • 291
  • 1
  • 2
  • 8
2
votes
2 answers

Find top log(n) or top sqt(n) values in an array of integers

Do you understand what this question means Find top log(n) or top sqt(n) values in an array of integers in less than linear time. If you don't, here is the question http://www.careercup.com/question?id=9337669. Could you please help me in…
bruceparker
  • 1,235
  • 1
  • 17
  • 33
2
votes
0 answers

Why is Math.hypot so slow?

I am performing a ton of distance calculations in my code, to the point where Math.sqrt(a*a + b*b) is run hundreds of thousands of times. I then recalled how there is a Math.hypot function that does exactly this. However, in all the testing I've…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
2
votes
1 answer

Integer Square root of a number

It's not that I don't understand how to find the integer square root of a number. I know several ways of finding them using Python and C++. It's just that this algorithm is really messing with my brain. And having to write it in SML is another…
Artique
  • 19
  • 3
2
votes
2 answers

I made a python script to easily find a square root but I can't stop it

I made a python script to find the square root of a number and prints out the result so far, but it uses an infinite loop and I cannot stop it. Does anybody know how to stop it when it has printed out the correct answer several times? I am looking…
Concode
  • 23
  • 6
2
votes
2 answers

Javascript for loop that calculates the square root of all numbers between two data numbers, added through a form

Only works with some numbers but is not working when i try to insert 3-10 for example. i don't know what is wrong. I'm still learning Javascript. Sorry for my bad english. Thank You let btn = document.getElementById("btn") let msg =…
Cecca86
  • 21
  • 1
2
votes
1 answer

How (and why) does "Python compute square roots of perfect squares exactly"?

This amazing code golf answer to Is this number Loeschian? in its entirety: Python, 49 bytes lambda n:0in[(n-3*i*i+0j)**.5%1for i in range(n)] Uses the equivalent quadratic form given on OEIS of n == 3*i*i+j*j. Check whether n-3*i*i is a perfect…
uhoh
  • 3,713
  • 6
  • 42
  • 95
2
votes
1 answer

Square root calculation using continued fractions to n bits of precision

This is an unsolved problem from my past arbitrary-precision rational numbers C++ assignment. For calculation, I used this expression from Wikipedia (a being the initial guess, r being its remainder): I ended up, just by guessing from experiments,…
2
votes
2 answers

Can someone explain me this function that finds the square root of an BigInteger in Java?

So I need to sqrt a BigInteger in pre Java 9 and I found below function to do that. I do understand the code, but I don't really get why its there. So I guess I don't really get the math behind it. Like why is (n / 32 + 8) used. Why is mid…
2
votes
0 answers

Recursive Function - Square Root Calculation - Too much recursion

I am attempting to write a function which provides results similar to the JavaScript built-in math.sqrt function. I am using the trial and error method where the function guesses, and then subsequently refines the guess for the square root of the…
2
votes
1 answer

CVXPY Square root of Singular Quadratic

I need to model sqrt(x^T C x) for a singular positive semidefinite matrix C. Here, it is proposed to use norm(Q*x) where Q is obtained from the Cholesky decomposition of C. How to take the square root of quad_form output in CVXPY? But,…
Behrooz Ns
  • 63
  • 5
2
votes
1 answer

Why would square root of 1 equals 1 returns false in java?

public static boolean checkSquare(int i){ return IntStream .rangeClosed(1, i/2) .anyMatch(x -> Math.sqrt(x) == i); } When I enter 1 as an user input, it return false. I don't understand why square root of 1 is not equals…
user10482378