Skip to content
Snippets Groups Projects
Commit 4f50c434 authored by HwangJungmok's avatar HwangJungmok
Browse files

Merge branch 'HanJungwoo' into 'master'

Han jungwoo

See merge request !8
parents 8e188bad 71a5a04b
No related branches found
No related tags found
1 merge request!8Han jungwoo
#include <stdio.h>
#include <math.h>
#include "fx_3132.h"
#include "fx_s3132.h"
fx_3132 sine(fx_3132 a) {
return double_to_fx(sin(fx_to_double(a)));
......
#include <stdio.h>
#include <math.h>
#define P2_2to32 4294967296.0
#define fx_to_double(a) a/P2_2to32
#define PI 3.141592653
#define fx_to_double(a) (a/P2_2to32)
#define double_to_fx(a) (long long)(a*P2_2to32)
#define fx_add(a, b) ((a)+(b))
#define fx_sub(a, b) ((a)-(b))
#define fx_mul(a, b) double_to_fx(fx_to_double (a) * fx_to_double (b))
#define fx_mul2(a, b) (double)a * (double)b / P2_2to32
#define fx_div(a, b) double_to_fx(fx_to_double (a) / fx_to_double (b))
#define fx_PI double_to_fx(3.141592653)
#define fx_sin(a) double_to_fx(sin(fx_to_double(a)))
#define fx_sqrt(a) double_to_fx(sqrt(fx_to_double(a)))
#define fx_power(a, b) double_to_fx(pow(fx_to_double(a), fx_to_double(b)))
#define fx_log10(a) double_to_fx(log10(fx_to_double(a)))
#define fx_ln(a) double_to_fx(log(fx_to_double(a)))
#define fx_PI() (double_to_fx(PI))
#define fx_PI_Reverse() (double_to_fx((1/PI)))
typedef long long fx_3132;
#include <stdio.h>
#include <math.h>
fx_3132 sine(fx_3132 a) {
return double_to_fx(sin(fx_to_double(a)));
};
fx_3132 sqrt1(fx_3132 a) {
return double_to_fx(sqrt(fx_to_double(a)));
};
fx_3132 power(fx_3132 a, fx_3132 b) {
return double_to_fx(pow(fx_to_double(a), fx_to_double(b)));
};
fx_3132 pi() {
return double_to_fx(fx_to_double(fx_PI));
};
fx_3132 piReverse() {
return double_to_fx((fx_to_double(1 / fx_PI)));
};
\ No newline at end of file
#include <stdio.h>
#include "fx_s3132_double.h"
#include "fx_s3132.h"
int main() {
int choose;
long long num1, num2;
double dnum1;
int a;
while (1) {
......@@ -38,7 +39,7 @@ int main() {
}
else if (choose == 2) {
printf("Choose the function.\n");
printf("1. Sine 2. Sqrt 3. Power\n");
printf("1. Sine 2. Sqrt 3. Power 4. log10 5. ln\n");
fflush(stdout);
scanf("%d", &a);
......@@ -47,14 +48,14 @@ int main() {
fflush(stdout);
scanf("%lld", &num1);
printf("Result: %lld\n", sine(num1));
printf("Result: %lld\n", fx_sin(num1));
}
else if (a == 2) {
printf("Input 1 fixed point number.\n");
fflush(stdout);
scanf("%lld", &num1);
printf("Result: %lld\n", sqrt1(num1));
printf("Result: %lld\n", fx_sqrt(num1));
}
else if (a == 3) {
printf("Input 2 fixed point number.\n");
......@@ -62,7 +63,21 @@ int main() {
scanf("%lld", &num1);
scanf("%lld", &num2);
printf("Result: %lld\n", power(num1, num2));
printf("Result: %lld\n", fx_power(num1, num2));
}
else if (a == 4) {
printf("Input 1 fixed point number.\n");
fflush(stdout);
scanf("%lld", &num1);
printf("Result: %lld\n", fx_log10(num1));
}
else if (a == 5) {
printf("Input 1 fixed point number.\n");
fflush(stdout);
scanf("%lld", &num1);
printf("Result: %lld\n", fx_ln(num1));
}
}
else if (choose == 3) {
......@@ -71,15 +86,17 @@ int main() {
fflush(stdout);
scanf("%d", &a);
if (a == 1) {
printf("Input 1 fixed point number.\n");
fflush(stdout);
scanf("%lld", &num1);
if (a == 1) {
printf("Result: %lld\n", fx_to_double(num1));
printf("Result: %lf\n", fx_to_double(num1));
}
else if (a == 2) {
printf("Result: %lld\n", double_to_fx(num1));
printf("Input 1 double number.\n");
fflush(stdout);
scanf("%lf", &dnum1);
printf("Result: %lld\n", double_to_fx(dnum1));
}
}
else if (choose == 4) {
......@@ -89,10 +106,10 @@ int main() {
scanf("%d", &a);
if (a == 1) {
printf("Result: %lld\n", pi());
printf("Result: %lld\n", fx_PI());
}
else if (a == 2) {
printf("Result: %lld\n", piReverse());
printf("Result: %lld\n", fx_PI_Reverse());
}
}
else if (choose == 5) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment