Using the Math package (in different programming languages) method sqrt to calculate the square root of a value.
Questions tagged [math.sqrt]
77 questions
0
votes
1 answer
How can I handle NaN with sqrt(-x)?
how can I make sqrt(-x) example: sqrt(-1.5) work, so I don't receive a NaN?
Tried to find the answer and now I understand how it works but still don't know how to do it properly. Thanks!
Context: exercise 67 (Variance) to calculate the sample…

smileess
- 1
0
votes
3 answers
Displaying sqrt when returning a function
I am just learning to code so i decided to make a project for myself making a function that finds the zero of a parabola. I think the issue i am having is actually printing out the sqrt.
This is the error I receive:
File…
0
votes
2 answers
What isnt my python code running?
my code is giving me some errors
Traceback (most recent call last):
File "python", line 7, in
ValueError: math domain error
import math
a= 3
b= 5
c= 2
d= b^2 -4*a*c
x1 = math.sqrt(d)
print(x1)

Manil Puri Manil
- 117
- 1
- 1
- 6
0
votes
4 answers
Get approximate square root
I'm implementing Babylonian method to approximate the square root of number n using following formula :
nextGuess = (lastGuess + n / lastGuess) / 2;
So when nextGuess and lasGuess are almost identical, nextGuess is the approximated square…
user7664681
0
votes
2 answers
Writing an isPrime function in java and using Math.sqrt
When writing an isPrime function to return a Boolean in Java, I have seen a lot of examples where people use Math.sqrt(number) in their for loop. Can someone explain why and what this function is doing in the for loop? I have attached an example…

Madeline Whitaker
- 1
- 1
- 1
0
votes
1 answer
Getting Error while using Math.Sqrt function in C#
In the program given below, Math.Sqrt function is throwing an error that is
"Expression denotes a variable', where amethod group' was expected."
What seems to be problematic here?
using System;
class program{
static void Main(){
…

Sagar Pawar
- 1
- 2
0
votes
1 answer
Performance of sqrt function on AArch64
I'm taking the performance of sqrt function on AArch64 for academic reasons.
Code for Single float sqrtf function:
fsqrt s0, s0
ret
Code for Double float sqrt function:
fsqrt d0, d0
ret
I'm referring to theoretical latencies for FSQRT from…

Vikram Dattu
- 801
- 3
- 8
- 24
0
votes
1 answer
why long, not int otherwise limit time exceed
Leetcode problem: valid perfect square
My answer is:
public class Solution {
public boolean isPerfectSquare(int num) {
int l = 0;
int r = (num>>1)+1;
while(l<=r) {
int mid = (l+r)>>1;
long temp =…

BAE
- 8,550
- 22
- 88
- 171
0
votes
4 answers
Output the square root just for the whole numbers
I need to Output the results of square root just for the whole numbers.
Example:
1 - 1
4 - 2
9 - 3
16 - 4...
up to 961 - 31... Which is the last square root before 1000.
Until now I have this... But, this is showing square roots for all numbers…

Philip Santana Dias
- 19
- 2
- 3
0
votes
0 answers
How fast is sqrt() in c++
I would like to ask about sqrt() function in library
in c++, I have an integer number and I want to know if there is an integer-square root fo this number...like 16 --> 4, and if not return -1
here is the function:
long long SQRT(Long long x)
{
…

E-mad Wahid
- 37
- 4
0
votes
1 answer
Within findNextPrime method, why do we need to find the square root of 'num', sqt, and use it in a for loop?
I'm trying to solve the beginner's problem of 'finding the next prime number after a given number'. I saw this code online and it works perfectly, but I can't seem to understand why, within findNextPrime method, we need to find the square root of…

Thor
- 9,638
- 15
- 62
- 137
0
votes
1 answer
math.sqrt returns 0
I have a c# function that contains formula to calculate euclidean distance of some points. I got the point's position defined by R(rx,ry) and L(lx,ly).
at first, I tried to write the code like this:
double dRightLeft = Math.Sqrt((Math.Pow(rx - lx,…

rfa
- 53
- 1
- 7
0
votes
1 answer
Sqrt method doesn't return number
I've got a method that computes two offsets for something else in my code. I wrote these offsets to the output and the result was: Isn't number. When I tryed to assign these values to another variables, these variables' value was 0.
This is my…

Sorashi
- 931
- 2
- 9
- 32
0
votes
1 answer
Always have 0 value from sqrt() in VC++
I have some problem with the fonction sqrt()! I'm quite a beginner so be indulgent please, the answer might be really simple. So here's my code:
#include
#include
using namespace std;
int main()
{
int touche;
int i;
…

user3502337
- 1
- 2
0
votes
2 answers
Graham Scan Algorithm -> sqrt and arctan2 huge values
I have to implement Graham Scan Algorithm.
This is my code:
/*
Graham's algorithm'
*/
#include
#include
#include
#include
#include
#include
#include…

dudeck
- 393
- 5
- 13