diff --git a/lec10/gptest.c b/lec10/gptest.c new file mode 100644 index 0000000000000000000000000000000000000000..2c0cabd0594143ecd1e74aa5416652bc37d417f6 --- /dev/null +++ b/lec10/gptest.c @@ -0,0 +1,46 @@ +#include <stdio.h> +// #### #### #### #### . #### #### #### #### +// S 15 . 16 +#define FX_Q_NUM 16 +#define FX_2_MINUS_16 1.52587890625e-05F +#define FX_2_PLUS_16 (1<<16) +#define FX_S_15_16 11516 +#define FX_SYSTEM FX_S_15_16 + +typedef int fixed32; + +fixed32 fromFloat(float fa) +{ + return (fixed32) (fa * FX_2_PLUS_16) ; +} + +float toFloat(fixed32 xa) +{ + return ((float) (xa)) * FX_2_MINUS_16 ; +} + +fixed32 fxAdd(fixed32 a, fixed32 b) +{ + return fromFloat((toFloat(a) + toFloat(b))); +} + +fixed32 fxAdd2(fixed32 a, fixed32 b) +{ + return a+b; +} + +int main() +{ + long long i=0; + int ia, ib, ic, ic2; + float fa; + // fscanf(stdin, "%d %d", &ia, &ib); + for ( i = 0; i < (long long) 256*256*256*256; i+=(256*256)) + { + ic = fxAdd(i, i); + ic2 = fxAdd2(i, i); + fprintf(stdout, "%f + %f : %f , %f diff = %d\n", toFloat(i), toFloat(i), toFloat(ic), toFloat(ic2), ic-ic2); + } + //fprintf(stdout, "%d + %d : %d\n", ia, ib , ic) ; + //fprintf(stdout, "%f + %f : %f\n", toFloat(ia), toFloat(ib), toFloat(ic)); +} diff --git a/lec10/test.c b/lec10/test.c index a283eb3969cf1c8311512a7e079a7e57d1bccbb4..bfef27ceb18c231aeaec25cddf3a2e114c197368 100644 --- a/lec10/test.c +++ b/lec10/test.c @@ -23,7 +23,7 @@ float toFloat_fn(fixed32 xa) fixed32 fxAdd(fixed32 a, fixed32 b) { - return fromFloat((toFloat(a) + toFloat(b))); + return (fixed32)(FX_2_PLUS_16 * ((((float) (a)) * FX_2_MINUS_16)+(((float) (b)) * FX_2_MINUS_16))); } fixed32 fxAdd2(fixed32 a, fixed32 b) diff --git a/test/pjtest.c b/test/pjtest.c new file mode 100644 index 0000000000000000000000000000000000000000..26953d3d873e4d35d06cf57273e9cc64c55dbc0f --- /dev/null +++ b/test/pjtest.c @@ -0,0 +1,4 @@ +#include <stdio.h> +int main(){ + printf("%d \n", ((1<<16)|(17<<8)|(14))); +}