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
00027
00045 arm_status arm_sqrt_q15(
00046 q15_t in,
00047 q15_t * pOut)
00048 {
00049 q15_t number, temp1, var1, signBits1, half;
00050 q31_t bits_val1;
00051 float32_t temp_float1;
00052
00053 number = in;
00054
00055
00056 if(number > 0)
00057 {
00058 signBits1 = __CLZ(number) - 17;
00059
00060
00061 if((signBits1 % 2) == 0)
00062 {
00063 number = number << signBits1;
00064 }
00065 else
00066 {
00067 number = number << (signBits1 - 1);
00068 }
00069
00070
00071 half = number >> 1;
00072
00073
00074 temp1 = number;
00075
00076
00077 temp_float1 = number * 3.051757812500000e-005f;
00078
00079
00080 bits_val1 = *(int *) &temp_float1;
00081
00082
00083 bits_val1 = 0x5f3759df - (bits_val1 >> 1);
00084
00085
00086 temp_float1 = *(float *) &bits_val1;
00087
00088
00089 var1 = (q31_t) (temp_float1 * 16384);
00090
00091
00092 var1 = ((q15_t)((q31_t) var1 * (0x3000 -
00093 ((q15_t)((((q15_t) (((q31_t) var1 * var1) >> 15)) * (q31_t) half) >> 15))) >>15)) << 2;
00094
00095 var1 = ((q15_t)((q31_t) var1 * (0x3000 -
00096 ((q15_t)((((q15_t) (((q31_t) var1 * var1) >> 15)) * (q31_t) half) >> 15))) >> 15)) << 2;
00097
00098 var1 = ((q15_t)((q31_t) var1 * (0x3000 -
00099 ((q15_t)((((q15_t) (((q31_t) var1 * var1) >> 15)) * (q31_t) half) >> 15))) >> 15)) << 2;
00100
00101
00102 var1 = ((q15_t) (((q31_t) temp1 * var1) >> 15)) << 1;
00103
00104
00105 if((signBits1 % 2) == 0)
00106 {
00107 var1 = var1 >> (signBits1 / 2);
00108 }
00109 else
00110 {
00111 var1 = var1 >> ((signBits1 - 1) / 2);
00112 }
00113
00114 *pOut = var1;
00115
00116 return (ARM_MATH_SUCCESS);
00117 }
00118
00119 else
00120 {
00121 *pOut = 0;
00122 return (ARM_MATH_ARGUMENT_ERROR);
00123 }
00124 }
00125