summaryrefslogtreecommitdiff
path: root/tests/test6/test6.c
blob: 3a78c0ccd047eafe69b550ad2862f912d136ed57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <math.h>
#include <stdio.h>

//#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, dbav[32]={0.f}, dbaf[32]={0.f};
	int i=0;
	for(f=1024000.f;f>1.f;f/=2.f) {
		dbaf[31-i]=f;
		dbav[31-i]=todB_a(&f);
		i++;
	}
	for (i=0;i<32;i++)
		printf("f==%f\tv==%f\n", dbaf[i], dbav[i]);

	return 0;
}