Is it possible to roll a significantly faster version of sqrt

Yes, it is possible even without trickery: sacrifice accuracy for speed: the sqrt algorithm is iterative, re-implement with fewer iterations. lookup tables: either just for the start point of the iteration, or combined with interpolation to get you all the way there. caching: are you always sqrting the same limited set of values? if so, … Read more

Comparing two values in the form (a + sqrt(b)) as fast as possible?

Here’s a version without sqrt, though I’m not sure whether it is faster than a version which has only one sqrt (it may depend on the distribution of values). Here’s the math (how to remove both sqrts): ad = a2-a1 bd = b2-b1 a1+sqrt(b1) < a2+sqrt(b2) // subtract a1 sqrt(b1) < ad+sqrt(b2) // square it … Read more

How do I calculate square root in Python?

Option 1: math.sqrt() The math module from the standard library has a sqrt function to calculate the square root of a number. It takes any type that can be converted to float (which includes int) as an argument and returns a float. >>> import math >>> math.sqrt(9) 3.0 Option 2: Fractional exponent The power operator … Read more

Is it possible to write Quake’s fast InvSqrt() function in Rust?

I don’t know how to encode the float number using integer format. There is a function for that: f32::to_bits which returns an u32. There is also the function for the other direction: f32::from_bits which takes an u32 as argument. These functions are preferred over mem::transmute as the latter is unsafe and tricky to use. With … Read more

Why does Python give the “wrong” answer for square root? What is integer division in Python 2? [duplicate]

In Python 2, sqrt=x**(1/2) does integer division. 1/2 == 0. So x(1/2) equals x(0), which is 1. It’s not wrong, it’s the right answer to a different question. If you want to calculate the square root without an import of the math module, you’ll need to use x**(1.0/2) or x**(1/2.). One of the integers needs … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)