Advertisement
nobs

sincos

Jun 20th, 2022 (edited)
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. /**
  2.  * sincos.c
  3.  *
  4.  * Demo für sincos direkt auf einer x86 FPU,
  5.  *
  6.  * clang sincos.c
  7.  *
  8.  * ./a.out
  9.  * -0.756802 -0.653644
  10.  *
  11.  */
  12.  
  13. #include <stdio.h>
  14.  
  15. int main(){
  16.     static double y asm("fpuy") =0.0;   // Sinus
  17.     static double x asm("fpux") =0.0;   // Kosinus
  18.     static double a asm("fpua") =0.0;   // Winkel
  19.  
  20.     scanf ("%lf", &a);                  // Winkel einlesen
  21.  
  22.     asm ("fldl (fpua)\n\t"              // Winkel auf den Register-Stack der FPU
  23.     "fsincos\n\t"                       // sin und cos mit einem Befehl in der FPU erzeugen
  24.     "fstpl (fpux)\n\t"                  // Kosinus aus der FPU in die Variable schreiben
  25.     "fstpl (fpuy)");                    // Sinus aus der FPU in die Variable schreiben
  26.  
  27.     printf ("sincos(%.17lf) -> sin: %.17lf cos: %.17lf\n", a, y, x);    // alles ausgeben
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement