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
2 answers

why is 'fast inverse square root' slower than 1/sqrt() at extremely large float?

The following full code could compare speed of fast inverse square root with 1/sqrt(). According to this sentence in wikipedia, (i.e. The algorithm was approximately four times faster than computing the square root with another method and…
San Tseng
  • 33
  • 1
  • 4
3
votes
2 answers

Use Of The Square Root Function From The Math Module

I know that I can find the square root of an expression using math.sqrt(x). I also know that I can find the square root using x**0.5. But why both? Isn't this non-pythonic? What is the use of math.sqrt() when we can just raise it to the 0.5th power?
defunct-user
  • 183
  • 1
  • 11
3
votes
1 answer

Implement sqrt method using the approximation approach. Cannot exit loop even the condition is false

I am so close to complete my practical question, just stuck at don't know why I cannot exit the loop after getting correct result. The question ask to implement sqrt method using the approximation approach. Let num is the number to apply sqrt…
wei
  • 937
  • 2
  • 14
  • 34
3
votes
2 answers

Quake inverse-square root: accuracy

The "magic" method of computing the inverse-square root, dating back to the Quake game apparently, is described in many sources. Wikipedia has a nice article on it: https://en.wikipedia.org/wiki/Fast_inverse_square_root I particularly found the…
alias
  • 28,120
  • 2
  • 23
  • 40
3
votes
2 answers

Calculating square root using only integer math in python

I'm working on a microcontroller that does not support floating point math. Integer math only. As such, there is no sqrt() function and I can't import any math modules. The MCU is running a subset of python that supports eight Python data types:…
cce1911
  • 363
  • 3
  • 20
3
votes
3 answers

Generic square root in Swift

I'm building a generic vector class in Swift with three types: Float, Double and Int. This works so far, but when I try to calculate the length of the vector I run into an issue. The formula for vector length is the square root of (x²+y²). But since…
user4207313
3
votes
1 answer

Android : Square and square root sign

I am creating an app where I need to show square root signs along with numbers. E.g. /¯¯¯¯¯¯¯¯¯¯¯ \/ (v^2) / T I am also looking to show square of a number. Can anyone help in displaying such text. This text comes from a database and can…
Kaustubh
  • 653
  • 6
  • 21
3
votes
4 answers

Computing the square root of 1000+ bit word in C

Imagine that we have e.g. 1000 bit word in our memory. I'm wondering if there is any way to calcuate a square root of it (not necessarily accurate, lets say without floating point part). Or we've got only memory location and later specified various…
3
votes
1 answer

How to let user use "sqrt()" + input to find square root of input?

I am still learning python so please be nice :) I want to let the user to do something like this: >> sqrt(4) #input 2 #output and >> sqrt(8) #input 2*rad(2) #if this is not possible, just say something like "not valid" and >> 4*4 #1st input 16…
Dark Leviathan
  • 489
  • 7
  • 19
3
votes
6 answers

Square root of negative numbers

Just wondering, is it possible to compute the square roots of negative numbers in C#? For example sqrt(-1) = i. I wrote this piece of code: using System; public static class sqrts { public static void Main() { string x; …
sirius_x
  • 183
  • 4
  • 11
3
votes
2 answers

Why `x = x*(1.5f-(xhalf*x*x));` can be a Newton Method iteration?

Ok, by far, I guess many people know the famous fast inverse square root (see more on Writing your own square root function and 0x5f3759df) Here is the code float FastInvSqrt(float x) { float xhalf = 0.5f * x; int i = *(int*)&x; // evil…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
3
votes
1 answer

Finding Square Root in C programming

I am trying to find the square root in C programming. But I am getting error as undefined reference to the sqrt. My Code is: #include #include void main(void){ int x; int y; printf("Enter two number numbers"); scanf("%d",…
Jaspreet Deol
  • 115
  • 1
  • 1
  • 12
3
votes
5 answers

Heron method in Python

Heron's method generates a sequence of numbers that represent better and better approximations for √n. The first number in the sequence is an arbitrary guess; every other number in the sequence is obtained from the previous number prev using the…
Snarre
  • 597
  • 5
  • 14
  • 22
3
votes
6 answers

Python - Fastest way to find all perfect squares in a given large number range

I am trying to write a method to get all the perfect squares in a given range in Python. A large range like between 2621163 and 520001400002. Now obviously iterating through the range and checking if a number is perfect like so def is_square(n): …
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
3
votes
2 answers

Square root of s15.16 fixed point number in Java

I want to write a function to calculate the square root of a s15.16 fixed point number. I know its a signed number with 15 digit int and 16 digit fraction. Is there anyway to do it without any libraries? Any other languages is fine too.
AliBZ
  • 4,039
  • 12
  • 45
  • 67