Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "arm_math.h"
00025 #include "arm_common_tables.h"
00026
00044 arm_status arm_sqrt_q31(
00045 q31_t in,
00046 q31_t * pOut)
00047 {
00048 q31_t number, temp1, bits_val1, var1, signBits1, half;
00049 float32_t temp_float1;
00050
00051 number = in;
00052
00053
00054 if(number > 0)
00055 {
00056 signBits1 = __CLZ(number) - 1;
00057
00058
00059 if((signBits1 % 2) == 0)
00060 {
00061 number = number << signBits1;
00062 }
00063 else
00064 {
00065 number = number << (signBits1 - 1);
00066 }
00067
00068
00069 half = number >> 1;
00070
00071
00072 temp1 = number;
00073
00074
00075 temp_float1 = number * 4.6566128731e-010f;
00076
00077
00078 bits_val1 = *(int *) &temp_float1;
00079
00080
00081 bits_val1 = 0x5f3759df - (bits_val1 >> 1);
00082
00083
00084 temp_float1 = *(float *) &bits_val1;
00085
00086
00087 var1 = (q31_t) (temp_float1 * 1073741824);
00088
00089
00090 var1 = ((q31_t)((q63_t) var1 * (0x30000000 -
00091 ((q31_t)((((q31_t) (((q63_t) var1 * var1) >> 31)) * (q63_t) half) >> 31))) >> 31)) << 2;
00092
00093 var1 = ((q31_t)((q63_t) var1 * (0x30000000 -
00094 ((q31_t)((((q31_t) (((q63_t) var1 * var1) >> 31)) * (q63_t) half) >> 31))) >> 31)) << 2;
00095
00096 var1 = ((q31_t)((q63_t) var1 * (0x30000000 -
00097 ((q31_t)((((q31_t) (((q63_t) var1 * var1) >> 31)) * (q63_t) half) >> 31))) >> 31)) << 2;
00098
00099
00100 var1 = ((q31_t) (((q63_t) temp1 * var1) >> 31)) << 1;
00101
00102
00103 if((signBits1 % 2) == 0)
00104 {
00105 var1 = var1 >> (signBits1 / 2);
00106 }
00107 else
00108 {
00109 var1 = var1 >> ((signBits1 - 1) / 2);
00110 }
00111
00112 *pOut = var1;
00113
00114 return (ARM_MATH_SUCCESS);
00115 }
00116
00117 else
00118 {
00119 *pOut = 0;
00120 return (ARM_MATH_ARGUMENT_ERROR);
00121 }
00122 }
00123