1 /** 2 * @file lv_vg_lite_math.h 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 10 #include "lv_vg_lite_math.h" 11 12 #if LV_USE_DRAW_VG_LITE 13 14 #include <stdint.h> 15 16 /********************* 17 * DEFINES 18 *********************/ 19 20 /********************** 21 * TYPEDEFS 22 **********************/ 23 24 /********************** 25 * STATIC PROTOTYPES 26 **********************/ 27 28 /********************** 29 * STATIC VARIABLES 30 **********************/ 31 32 /********************** 33 * MACROS 34 **********************/ 35 36 /********************** 37 * GLOBAL FUNCTIONS 38 **********************/ 39 math_fast_inv_sqrtf(float number)40float math_fast_inv_sqrtf(float number) 41 { 42 const float threehalfs = 1.5f; 43 44 float x2 = number * 0.5f; 45 float y = number; 46 int32_t i = *(int32_t *)&y; /* evil floating point bit level hacking */ 47 48 i = 0x5f3759df /* floating-point representation of an approximation of {\sqrt {2^{127}}}} see https://en.wikipedia.org/wiki/Fast_inverse_square_root. */ 49 - (i >> 50 1); 51 y = *(float *)&i; 52 y = y * (threehalfs - (x2 * y * y)); /* 1st iteration */ 53 54 return y; 55 } 56 57 /********************** 58 * STATIC FUNCTIONS 59 **********************/ 60 61 #endif /*LV_USE_DRAW_VG_LITE*/ 62