Computes the square root of a number. There are separate functions for Q15, Q31, and floating-point data types. When a CPU with FPU is used, the instruction fsqrts
is used to compute the result, while a CPU without FPU, Newton-Raphson algorithm is used. For Newton-Raphson algorithm, this is an iterative algorithm of the form:
x1 = x0 - f(x0)/f'(x0)
where x1
is the current estimate, x0
is the previous estimate, and f'(x0)
is the derivative of f()
evaluated at x0
. For the square root function, the algorithm reduces to:
x0 = in/2 [initial guess]
x1 = 1/2 * ( x0 + in / x0) [each iteration]
- Parameters
-
[in] | in | input value. |
[out] | pOut | square root of input value. |
- Returns
- The function returns CSKY_MATH_SUCCESS if input value is positive value or CSKY_MATH_ARGUMENT_ERROR if
in
is negative value and returns zero output for negative values.
- Parameters
-
[in] | in | input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF. |
[out] | *pOut | square root of input value. |
- Returns
- The function returns CSKY_MATH_SUCCESS if the input value is positive and CSKY_MATH_ARGUMENT_ERROR if the input is negative. For negative inputs, the function returns *pOut = 0.
- Parameters
-
[in] | in | input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF. |
[out] | *pOut | square root of input value. |
- Returns
- The function returns CSKY_MATH_SUCCESS if the input value is positive and CSKY_MATH_ARGUMENT_ERROR if the input is negative. For negative inputs, the function returns *pOut = 0.
- Note
- When the hard float instruction
fsqrts
is used, the accuracy will be lost from 3 LSB to 7 LSB. So as the functions, who call this function.