FLOAT computeT(int n, FLOAT a, FLOAT b, FLOAT (*fun)(FLOAT)) { int k; FLOAT s,h; h = F_div_int((b - a), n); s = F_div_int(fun(a) + fun(b), 2 ); for(k = 1; k < n; k ++) { s += fun(a + F_mul_int(h, k)); } s = F_mul_F(s, h); return s; }
FLOAT sqrt(FLOAT x) { FLOAT dt, t = int2F(2); do { dt = F_div_int((F_div_F(x, t) - t), 2); t += dt; } while(Fabs(dt) > f2F(1e-4)); return t; }
FLOAT computeT(int n, FLOAT a, FLOAT b, FLOAT (*fun)(FLOAT)) { int k; FLOAT s,h; h = F_div_int((b - a), n); s = F_div_int(fun(a) + fun(b), 2 ); for(k = 1; k < n; k ++) { s += fun(a + F_mul_int(h, k)); } s = F_mul_F(s, h); return s; /* FLOAT m1=f2F(0.1); //FLOAT m2=f2F(); m1=fun(m1); FLOAT ans=f2F(0.8); ans=Fabs(ans-m1); nemu_assert(ans<=f2F(1e-4)); return 0; */ }