sqrt Questions

4

Solved

Unfortunately, the standard C++ library doesn't have a single call for sincos, which gives a place for this question. First question: If I want to calculate a sin and a cos, is it cheaper to calc...
Universe asked 13/9, 2013 at 19:38

5

I was asked to calculate the following nested root expression using recursion only. I wrote the code below that works, but they allowed us to use only one function and 1 input n for the purpose ...
Hormone asked 4/4, 2020 at 16:58

10

Solved

I need to calculate the square root of some numbers, for example √9 = 3 and √2 = 1.4142. How can I do it in Python? The inputs will probably be all positive integers, and relatively small (say less...
Apulia asked 20/1, 2022 at 21:16

4

Solved

What is the difference between x**(1/2) , math.sqrt() and cmath.sqrt()? Why does cmath.sqrt() get complex roots of a quadratic right alone? Should I use that for my square roots exclusively? What...
Herminiahermione asked 13/11, 2015 at 2:25

8

Solved

We find various tricks to replace std::sqrt (Timing Square Root) and some for std::exp (Using Faster Exponential Approximation) , but I find nothing to replace std::log. It's part of loops in my pr...
Primo asked 2/10, 2016 at 20:27

14

Solved

Is there an integer square root somewhere in python, or in standard libraries? I want it to be exact (i.e. return an integer), and raise an exception if the input isn't a perfect square. I tried us...
Venatic asked 13/3, 2013 at 16:19

5

Solved

#include <iostream> #include <cmath> using namespace std; int main() { double a = sqrt(2); cout << a << endl; } hi this is the program to find sqrt of 2 it prints just...
Isidraisidro asked 12/3, 2013 at 13:6

6

I want to design a synthesizable module in Verilog which will take only one cycle in calculating square root of given input of 32 bit.
Odelle asked 7/1, 2016 at 9:50

1

Solved

Specifically, this is the code I'm talking about: float InvSqrt(float x) { float xhalf = 0.5f*x; int i = *(int*)&x; // warning: strict-aliasing UB, use memcpy instead i = 0x5f375a86- (i >...
Royceroyd asked 24/3, 2022 at 19:5

2

I practice for an exam in Java. One of the questions I faced today is: Given an array with n numbers, I need to check if there are 2 subarrays(doesn't have to be equal) that their multiplication eq...
Ligamentous asked 22/12, 2018 at 18:57

7

Solved

In my program, I am trying to take the find the largest prime factor of the number 600851475143. I have made one for loop that determines all the factors of that number and stores them in a vector ...
Entropy asked 7/3, 2014 at 0:28

2

Solved

With Perl, one could use bignum to set the level of precision for all operators. As in: use bignum ( p => -50 ); print sqrt(20); # 4.47213595499957939281834733746255247088123671922305 With Rak...
Poona asked 19/8, 2020 at 9:43

7

Solved

I find myself typing double foo=1.0/sqrt(...); a lot, and I've heard that modern processors have built-in inverse square root opcodes. Is there a C or C++ standard library inverse square root f...
Agma asked 16/10, 2012 at 21:25

1

Solved

I wondering why the compiler let this pass and is giving the right output, although sqrt() from its prototype normally should only get an double value as argument: In C99 the declaration of the pr...
Karleen asked 12/12, 2019 at 18:11

3

This is just to satisfy my own curiosity. Is there an implementation of this: float InvSqrt (float x) { float xhalf = 0.5f*x; int i = *(int*)&x; i = 0x5f3759df - (i>>1); x = *(float...
Ischium asked 28/11, 2019 at 4:45

3

Solved

I am looking for a C++ function that returns the inverse sqrt of a float: rsqrt(x) = 1/sqrt(x) by using the exact method like the built-in XMM operation RSQRTSS (cf. https://www.felixcloutier.com/x...
Wretch asked 29/10, 2019 at 19:31

6

I am in a need of fast integer square root that does not involve any explicit division. The target RISC architecture can do operations like add, mul, sub, shift in one cycle (well - the operation's...
Inclose asked 29/6, 2015 at 13:52

5

Solved

As part of a program that I'm writing, I need to compare two values in the form a + sqrt(b) where a and b are unsigned integers. As this is part of a tight loop, I'd like this comparison to run as ...
Prefatory asked 8/5, 2019 at 8:58

3

Solved

I am looking for the best inverse square root algorithm for fixed point 16.16 numbers. The code below is what I have so far(but basically it takes the square root and divides by the original number...
Connotation asked 8/6, 2011 at 23:23

9

Solved

I was finding out the algorithm for finding out the square root without using sqrt function and then tried to put into programming. I end up with this working code in C++ #include <iostream&gt...
Selfstarter asked 26/10, 2013 at 19:54

2

Just curiosity about the standard sqrt() from math.h on GCC works. I coded my own sqrt() using Newton-Raphson to do it!
Proem asked 12/2, 2019 at 4:7

2

I'm playing around with swift and have the following simple code I want to check how "sqrt" function is implemented, so I tried to click on "Darwin.C.math" link but nothing happened. I googled ...
Chimborazo asked 14/3, 2017 at 10:8

2

Solved

Please help me to write a function to compute the square root of positive real numbers using the formula: x i+1 = (1/2) * (xi + (A / x1)), where 'A' - input real number. On the zero iteration n...
Causal asked 23/9, 2018 at 17:18

5

Solved

x = 16 sqrt = x**(.5) #returns 4 sqrt = x**(1/2) #returns 1 I know I can import math and use sqrt, but I'm looking for an answer to the above. What is integer division in Python 2? This beh...
Yonita asked 7/3, 2012 at 2:48

4

Solved

What causes the problem? from math import sqrt print "a : " a = float(raw_input()) print "b : " b = float(raw_input()) print "c : " c = float(raw_input()) d = (a + b +...
Northwester asked 31/3, 2015 at 18:36

© 2022 - 2024 — McMap. All rights reserved.