Square Root

__STATIC_FORCEINLINE riscv_status riscv_sqrt_f32(float32_t in, float32_t * pOut)
riscv_status riscv_sqrt_q31(q31_t in, q31_t *pOut)
riscv_status riscv_sqrt_q15(q15_t in, q15_t *pOut)
void riscv_vsqrt_f32(float32_t *pIn, float32_t *pOut, uint16_t len)
void riscv_vsqrt_q31(q31_t *pIn, q31_t *pOut, uint16_t len)
void riscv_vsqrt_q15(q15_t *pIn, q15_t *pOut, uint16_t len)
group SQRT

Computes the square root of a number. There are separate functions for Q15, Q31, and floating-point data types. The square root function is computed using the Newton-Raphson algorithm. This is an iterative algorithm of the form:

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:

Functions

__STATIC_FORCEINLINE riscv_status riscv_sqrt_f32(float32_t in, float32_t * pOut)

Floating-point square root function.

Return

execution status

  • RISCV_MATH_SUCCESS : input value is positive

  • RISCV_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0

Parameters
  • [in] in: input value

  • [out] pOut: square root of input value

riscv_status riscv_sqrt_q31(q31_t in, q31_t *pOut)

Q31 square root function.

Return

execution status

  • RISCV_MATH_SUCCESS : input value is positive

  • RISCV_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0

Parameters
  • [in] in: input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF

  • [out] pOut: points to square root of input value

riscv_status riscv_sqrt_q15(q15_t in, q15_t *pOut)

Q15 square root function.

Return

execution status

  • RISCV_MATH_SUCCESS : input value is positive

  • RISCV_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0

Parameters
  • [in] in: input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF

  • [out] pOut: points to square root of input value

void riscv_vsqrt_f32(float32_t *pIn, float32_t *pOut, uint16_t len)

Vector Floating-point square root function.

Return

The function returns RISCV_MATH_SUCCESS if input value is positive value or RISCV_MATH_ARGUMENT_ERROR if in is negative value and returns zero output for negative values.

Parameters
  • [in] pIn: input vector.

  • [out] pOut: vector of square roots of input elements.

  • [in] len: length of input vector.

void riscv_vsqrt_q31(q31_t *pIn, q31_t *pOut, uint16_t len)
void riscv_vsqrt_q15(q15_t *pIn, q15_t *pOut, uint16_t len)