Using the Math package (in different programming languages) method sqrt to calculate the square root of a value.
Questions tagged [math.sqrt]
77 questions
2
votes
5 answers
I'm creating a calculator using with HTML, CSS and Javascript. I'm stuck at the square root function
So I am creating a calculator using HTML,CSS and javascript. I need to add a square root function to calculate the square root of a number using Math.sqrt(x) along with other functions but I am stuck at square root. I can't seem to get it to work,…

Emma
- 23
- 1
- 4
2
votes
2 answers
Why does this prime checker work, and not work if I try to make it more efficient
Below is one of the first programs I made (with help from the Internet) in Java. It is a program that checks if a given integer is prime or not and prompts the user with feedback. If the user input is not an integer it outputs that it is not an…

user2609980
- 10,264
- 15
- 74
- 143
2
votes
2 answers
Make JavaScript Math.sqrt() print more digits
If I write document.write(Math.sqrt(2)) on my HTML page, I get 1.4142135623730951.
Is there any way to make the method output more than 16 decimal places?

Bluefire
- 13,519
- 24
- 74
- 118
1
vote
1 answer
Why is my C# calculation being returned as a NaN?
I'm doing the C# Unity course on Coursera and the first assignment is doing my head in. Yes I'm new to programming so please cut me some slack.
I'm trying to calculate the distance of the hypotenuse between two character locations.
I am forced to…

Brendin Venter
- 29
- 1
1
vote
1 answer
Not getting correct output when using command line argument in java
//Square root of a no. using command line argument
class Calculator {
double i;
double x = Math.sqrt(i);
}
class SquareRoot {
public static void main(String arg[]) {
Calculator a = new Calculator();
a.i =…

Aps
- 13
- 5
1
vote
0 answers
What's the best way to take the square root of an int?
I ended up writing this recently to get around a problem that math.sqrt deals in floats:
for i := 2; i < int(math.Ceil(math.Sqrt(float64(n)))); {
I had to look away from the editor while doing it, but it worked.
If a wandering helpful Gopher…

cryptograthor
- 455
- 1
- 7
- 19
1
vote
1 answer
math.sqrt() ValueError: math domain error
Im trying to plot out a graph with matplotlib and calculus, but the math.sqrt() of my f(x) function doesnt work. I need to sqhare root 2*x-1. As seen in the code
import matplotlib.pyplot as plt
import math
def f(x):
return…

TrackLab
- 32
- 1
- 7
1
vote
3 answers
Python: using the math.sqrt function in a complex equation
I am trying to write code to solve this python exercise: I must use the 'math' library, sqrt and possibly pow functions.
"The distance between two points x and y is the square root of the sum
of squared differences along each dimension of x and…

avwinter
- 83
- 2
- 10
1
vote
1 answer
check if number is equal to the square root of another number c#
I want to see if a number is equal to the square root of another. I wrote a method to achieve this, but it would search until the maximum Int32 value (which would take a long time). I really would like to search beyond numbers greater than 100 (the…

jakedacatman
- 21
- 7
1
vote
0 answers
Math domain error using math.sqrt in Python
I have a for loop which calculates a square root but for some iterations (i.e. for some values of Pos1) the expression under the square root is negative and hence the square root is impossible to calculate in the real domain and Python returns the…

Blazej Kowalski
- 367
- 1
- 6
- 16
1
vote
2 answers
Detect if a double is a perfect square in Java
I want to detect if a double, like 6.25 is a perfect square or not.
To detect perfect squares for those numbers whose square root is an integer, I would do something like
public boolean isPerfectDouble( double i )
{
if…

tubby
- 2,074
- 3
- 33
- 55
1
vote
0 answers
Python square-root of large int inconsistant?
I am trying to perform a relatively simple operation (square-root) using python 3.6 on a rather large integer as follows:
import math
y = math.sqrt(y_square)
print(y_square)
print(y)
print(y**2 - y_square)
Which yields:
y_square =…

Clara-sininen
- 191
- 2
- 9
1
vote
5 answers
How to turn each element of array into a square root and sum them up
I'm just starting to learn JavaScript and I have to do a task:
Create function with local variables which turns each element of array [0,1,2,3,4,5] into a sqrt and sums them up.
I know how to do a function and then I have to do a loop - I have a…

asheri
- 15
- 1
- 7
1
vote
1 answer
Triangle Tester
I have created a Triangle class program, but I need a tester class for it. In the tester class, it must ask the user to input the points, and then it would calculate the sides and so fourth. How do I ask the user to input x1 and y1 in the tester,…

Nosferatu2
- 21
- 3
1
vote
1 answer
Actual performance benefits of distance squared vs distance
When calculating the distance between two 3D points in Java, I can compute the distance, or the distance squared between them, avoiding a call to Math.sqrt.
Natively, I've read that sqrt is only a quarter of the speed of multiplication which makes…

konsolas
- 1,041
- 11
- 24