1.4.4.17 Fract_sqrtQ15 Function

fract_q15_t Fract_sqrtQ15(fract_q15_t X)

Summary

Fixed point Q15 squareroot.

Description

Returns square root of Q15 (Q0.15) fraction. Since -1 <= X < 1, we know that the 0<= SquareRoot(||X||) < 1.

Preconditions

None.

Parameters

X Q15 input, should be non-negative.

Returns

Square root of abs(X).

Remarks

Given integer X, solve for Y such that

Y Y X

---- * ---- = ----

2^15 2^15 2^15

This is equivalent to Y * Y = X * 2^15 = X<<15

So as integers:

Y = integer sqrt(X<<15) thus

fixed_point_sqrt(X) = integer_sqrt(X<<15)

For X = 0,1,...32767, define ErrSqrt = (sqrt(X/32768.0) - FixedPointSQRT(X))/sqrt(X/32768.0)

This error ranges from 0 to 0.015259, with an average error of 0.0054096

The fast integer square root function used is based on http://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2

C

fract_q15_t Fract_sqrtQ15 (fract_q15_t X );