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

How to square the value and sum together in javascript

In Javascript, I have a scenario to implement the following: Let's take a list of integer below, take each integer in that list and double the value, then square the doubled value, then as output, sum together all the squared values.…
UI_Dev
  • 3,317
  • 16
  • 46
  • 92
2
votes
2 answers

Roots of a quadratic function: math domain error

I want to define a function that returns the values of the roots. It is supposed to return always something. If b**2 - 4ac < 0, then it is supposed to return [ ], but it appears as an error. My code is this by now: from math import* def…
Anonymous
  • 49
  • 1
  • 9
2
votes
3 answers

Fastest algorithm of getting precise answer (not approximated) when square-rooting

Sorry for unclear title, but I don't know how to state it properly (feel free to edit), so I will give example: sqrt(108) ~ 10.39... BUT I want it to be like this sqrt(108)=6*sqrt(3) so it means expanding into two numbers So that's my algorithm i =…
Templar
  • 1,843
  • 7
  • 29
  • 42
2
votes
1 answer

Accuracy of integer sqrt using double

I would like to compute the integer part of an uint64_t. For 32-bit uint32_t, it is frequently recommended to first cast it to double, sqrt and then cast it back to uint32_t. Does it work for uint64_t as well, given that double can exactly…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
2
votes
1 answer

Problems finding a number's square root with bisection method

#include #include using namespace std; double bisection(double errorVal, double userNum){ double upper=userNum, lower=0; double mid=(lower+upper)/2.0;; while(mid*mid!=userNum){ double mid=(lower+upper)/2.0; …
2
votes
1 answer

Square root source code found on the net

I'm looking for some algorithm for square root calculation and found this source file. I would like to try to replicate it because it seems quite simple but I can not relate it to some known algorithm (Newton, Babylon ...). Can you tell me the…
alukard990
  • 811
  • 2
  • 9
  • 14
2
votes
3 answers

Fast integer sqrt upper bound approximation

This is a question, regarding my homework, specifically on NASM. I am writing an algorithm to find the least whole factor of a number. (Greater than 1) In pseudo-code it can be summed up as: if(n%2==0) return 2; for(i=3; i <= n/2; i+=2) …
RuRo
  • 311
  • 4
  • 17
2
votes
1 answer

Calculating Square Root recursively in Scala

The following code works but I don't quite understand how the arguments are mapped to the parameter lists. Please be aware Im new to Scala. import Math.abs val tolerance = 0.0001 def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) / x <…
Eddie
  • 1,043
  • 8
  • 14
2
votes
1 answer

Using a while loop to compute the approximation of a square root of a number

I am trying to compute the square root of a number using function containing a while loop. Within the conditions of the while loop, I want to compare the absolute value of the ratio of the two values, the guessed square root and the number, to 1.…
user5588864
2
votes
1 answer

Seeding square roots on FPGA in VHDL for Fixed Point

I'm attempting to create a fixed-point square root function for a Xilinx FPGA (hence real types are out, and David Bishops ieee_proposed library is also unsupported for XST synthesis). I've settled on a Newton-Raphson method to calculate the…
davidhood2
  • 1,367
  • 17
  • 47
2
votes
4 answers

What is an efficient algorithm to find all the factors of an integer?

I was writing a very simple program to examine if a number could divide another number evenly: // use the divider squared to reduce iterations for(divider = 2; (divider * divider) <= number; divider++) if(number % divider == 0) print("%d…
edhu
  • 449
  • 6
  • 23
2
votes
3 answers

C++ Square Root Function Bug

I have a c++ algorithm that calculates the square root of an integer. The program works with the exception of a single flaw. It is unable to calculate the square root of a number that is below 1. For example, it cant calculate the square root of .5…
Gabriel
  • 346
  • 5
  • 24
2
votes
3 answers

How to write a Square root in android studio

What's the best practice to make a square root function in android in text form (ex. Quadratic equation). Could I do it in HTML in my XML file possibly? Or would have have to do it under java
user4914918
  • 91
  • 1
  • 3
  • 10
2
votes
3 answers

Square Root in C/C++

I am trying to implement my own square root function which gives square root's integral part only e.g. square root of 3 = 1. I saw the method here and tried to implement the method int mySqrt(int x) { int n = x; x = pow(2, ceil(log(n) /…
adrian008
  • 395
  • 6
  • 18
2
votes
1 answer

how do you find the square root of a number in applescript

I have a simple calculator code and I want to include square root in it. I am relatively new to applescript and I have no idea how. It might be nooby but thanks anyway!
samrockw22
  • 59
  • 6