/*
 * test source file for assembling to ELF
 * build with:
 *    nasm -f elf elftest.asm
 *    gcc -o elftest elftest.c elftest.o
 * (assuming your gcc is ELF)
 */


#include <stdio.h>
#include <time.h>

extern double SinusTaylor(double);
extern double SinusFPU(double);

int main(void) {
    
    double taylor, fpu, x;
    long loop, starttime;
    double pi = 3.14159265358979323846;
    
    printf("\nBitte Zahl eingeben\n");
    printf("\nx = ");
    scanf("%le", &x);
    
    while (x > pi) {            // solang x größer als pi
        x = x - (pi * 2);       // um eine Periode nach links hüpfen
    }
    
    while (x < -pi) {           // solang x kleiner als -pi
        x = x + (pi * 2);       // um eine Periode nach rechts hüpfen
    }
    
    if (x > (pi / 2)) {         // jetzt noch x in den Bereich zwischen
        x = pi - x;             // -0.5pi und +0.5pi bringen, weil da die
    } else if (x < -(pi / 2)) { // Genauigkeit am besten ist ...
        x = -pi - x;
    }
    
    taylor = SinusTaylor(x);    // ... und losrechnen
    fpu = SinusFPU(x);
    /* erg wird in EAX-Register (integer) oder ST0 (float) zurueckgegeben */
    
    printf("\nTaylor-Berechnung: sin(x) = %.15f\n", taylor);
    printf("FPU-Berechnung:    sin(x) = %.15f\n", fpu);
    
/*  printf("\nZeitmessung\n");
    starttime = clock();
    for (loop = 0; loop < 100000; loop++) {
        SinusTaylor(x);
    }
    printf("Taylor-Berechnung: %1d\n", clock() - starttime);
    starttime = clock();
    for (loop = 0; loop < 100000; loop++) {
        SinusFPU(x);
    }
    printf("FPU-Berechnung:    %1d\n", clock() - starttime);
*/  
    return (0);
    
}

