#include #include //#if 1 //(UGLY_IEEE754_FLOAT32_HACK :-) /* static inline float todB_a(const float *x){ return (float)((*(int *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f; } */ static inline float todB_a(const float *x){ union { //int32_t i; int i; float f; } ix; ix.f = *x; ix.i = ix.i&0x7fffffff; return (float)(ix.i * 7.17711438e-7f -764.6161886f); } //#else static inline float todB_a2(const float *x){ return (*(x)==0?-400.f:logf(*(x)**(x))*4.34294480f); } //#endif int main() { float f; for(f=1.f;f<100000000.f;f*=1.2f) printf("%f\t%f\n", todB_a(&f), todB_a2(&f)); return 0; }