Skip to content
Snippets Groups Projects
Select Git revision
  • b3ec647b36926f14671ca51dfba018ae59f43715
  • main default protected
2 results

README.md

Blame
  • Forked from 연우 최 / git-exercise
    Source project has a limited visibility.
    test.c 2.17 KiB
    #include<stdio.h>
    #include "fx_s4716_double.h"
    
    extern void fx_to_double(fx_s4716 a);
    extern void double_to_fx(double a);
    extern void fx_add(fx_s4716 a, fx_s4716 b);
    extern void fx_sub(fx_s4716 a, fx_s4716 b);
    extern void fx_mul(fx_s4716 a, fx_s4716 b);
    extern void fx_div(fx_s4716 a, fx_s4716 b);
    extern void fx_pi();
    extern void fx_inv_pi();
    extern void fx_sqrt(fx_s4716 a);
    extern void fx_pow(fx_s4716 a);
    
    int main()
    {
        fx_s4716 a,b;
        double c;
        int option;
        printf("This is program to test fixed point arithmetic\n");
        printf("   OPTION \n");
        printf("0. add \n");
        printf("1. subtract \n");
        printf("2. multiply \n");
        printf("3. divide \n");
        printf("4. square root \n");
        printf("5. power \n");
        printf("6. print PI \n");
        printf("7. print inverse PI \n");
        printf("8. fix to double \n");
        printf("9. double to fix \n");
        printf("10. quit\n\n");
    
        printf("Type option : ");
        fflush(stdout);
        scanf("%d", &option);
        switch (option)
        {
        case 0:
            printf("Input two number : "); fflush(stdout);
            scanf("%lld %lld", &a, &b);
            fx_add(a, b);
            break;
        case 1:
            printf("Input two number : "); fflush(stdout);
            scanf("%lld %lld", &a, &b);
            fx_sub(a, b);
            break;
        case 2:
            printf("Input two number : "); fflush(stdout);
            scanf("%lld %lld", &a, &b);
            fx_mul(a, b);
            break;
        case 3:
            printf("Input two number : "); fflush(stdout);
            scanf("%lld %lld", &a, &b);
            fx_div(a, b);
            break;
        case 4:
            printf("Input one number : "); fflush(stdout);
            scanf("%lld", &a);
            fx_sqrt(a);
            break;
        case 5:
            printf("Input one number : "); fflush(stdout);
            scanf("%lld", &a);
            fx_pow(a);
            break;
        case 6:
            fx_pi();
            break;
        case 7:
            fx_inv_pi();
            break;
        case 8:
            printf("Input fix number : "); fflush(stdout);
            scanf("%lld",&a);
            fx_to_double(a);
            break;
        case 9:
            printf("Input double number : "); fflush(stdout);
            scanf("%lf",&c);
            double_to_fx(c);
            break;
        default:
            break;
        }
    }