ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_sqrt_f32_ansi.c
Go to the documentation of this file.
1// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "dsps_sqrt.h"
16#include <math.h>
17
18
19inline float dsps_sqrtf_f32_ansi(float f)
20{
21 int result;
22 int *f_ptr = (int *)&f;
23 result = 0x1fbb4000 + (*f_ptr >> 1);
24 const int *p = &result;
25 float *f_result = (float *)p;
26 return *f_result;
27}
28
29esp_err_t dsps_sqrt_f32_ansi(const float *input, float *output, int len)
30{
31 if (NULL == input) {
33 }
34 if (NULL == output) {
36 }
37
38 for (int i = 0 ; i < len ; i++) {
39 output[i] = dsps_sqrtf_f32_ansi(input[i]);
40 }
41 return ESP_OK;
42}
43
45{
46 const float x2 = data * 0.5F;
47 const float threehalfs = 1.5F;
48
49 union {
50 float f;
51 uint32_t i;
52 } conv = {data}; // member 'f' set to value of 'data'.
53 conv.i = 0x5f3759df - ( conv.i >> 1 );
54 conv.f *= ( threehalfs - ( x2 * conv.f * conv.f ) );
55 return conv.f;
56}
#define ESP_ERR_DSP_PARAM_OUTOFRANGE
esp_err_t dsps_sqrt_f32_ansi(const float *input, float *output, int len)
square root approximation
float dsps_inverted_sqrtf_f32_ansi(float data)
inverted square root approximation
float dsps_sqrtf_f32_ansi(float f)
square root approximation
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
static float data[128 *2]
Definition test_fft2r.c:34