Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float raiz1(float n) {
- int i = 0;
- float aux = 1.0;
- for (i = 0; i < 10; ++i) {
- aux = aux - ((aux * aux) - n) / (2 * aux);
- }
- return aux;
- }
- typedef unsigned short u16;
- #define P 3
- u16 raiz2(u16 n) {
- int i = 0;
- u16 aux = (1 << P); /* 3 casas (binarias) de precisao */
- n <<= P;
- for (i = 0; i < 10; ++i) {
- aux = aux - ((((aux * aux) >> P) - n) << P) / (((2 << P) * aux) >> P);
- }
- return aux;
- }
- int main() {
- float a = 56;
- printf("%f %f %f\n", sqrt(a), raiz1(a), raiz2(56) / pow(2.0, P));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement