home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / mathffp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  2.0 KB  |  61 lines

  1. #include <exec/types.h>
  2. #include <libraries/mathffp.h>
  3.  
  4. #include <clib/mathffp_protos.h>
  5. #include <clib/alib_protos.h>
  6.  
  7. struct Library *MathBase;
  8.  
  9. UBYTE st1[80] = "3.1415926535897";
  10. UBYTE st2[80] = "2.718281828459045";
  11. UBYTE st3[80], st4[80];
  12.  
  13. VOID main()
  14. {
  15. FLOAT num1, num2;
  16. FLOAT n1, n2, n3, n4;
  17. LONG  exp1, exp2, exp3, exp4;
  18. LONG  mant1, mant2, mant3, mant4;
  19. LONG  place1, place2;
  20.  
  21. if (MathBase = OpenLibrary("mathffp.library", 33))
  22.     {
  23.  
  24.     n1 = afp(st1);            /* Call afp entry */
  25.     n2 = afp(st2);            /* Call afp entry */
  26.     printf("\n\nASCII %s converts to floating point %f", st1, n1);
  27.     printf("\nASCII %s converts to floating point %f", st2, n2);
  28.  
  29.     num1 = 3.1415926535897;
  30.     num2 = 2.718281828459045;
  31.  
  32.     exp1 = fpa(num1, st3);    /* Call fpa entry */
  33.     exp2 = fpa(num2, st4);    /* Call fpa entry */
  34.     printf("\n\nfloating point %f converts to ASCII %s", num1, st3);
  35.     printf("\nfloating point %f converts to ASCII %s", num2, st4);
  36.  
  37.     place1 = -2;
  38.     place2 = -1;
  39.     arnd(place1, exp1, st3);    /* Call arnd entry */
  40.     arnd(place2, exp2, st4);    /* Call arnd entry */
  41.     printf("\n\nASCII round of %f to %d places yields %s", num1, place1, st3);
  42.     printf("\nASCII round of %f to %d places yields %s", num2, place2, st4);
  43.  
  44.     exp1  = -3;   exp2  = 3;    exp3  = -3;   exp4  = 3;
  45.     mant1 = 12345;  mant2 = -54321;  mant3 = -12345; mant4 = 54321;
  46.  
  47.     n1 = dbf(exp1, mant1);        /* Call dbf entry */
  48.     n2 = dbf(exp2, mant2);        /* Call dbf entry */
  49.     n3 = dbf(exp3, mant3);        /* Call dbf entry */
  50.     n4 = dbf(exp4, mant4);        /* Call dbf entry */
  51.     printf("\n\ndbf of exp = %d and mant = %d yields FFP number of %f", exp1, mant1, n1);
  52.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f", exp2, mant2, n2);
  53.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f", exp3, mant3, n3);
  54.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f", exp4, mant4, n4);
  55.  
  56.     CloseLibrary(MathBase);
  57.     }
  58. else
  59.     printf("Can't open mathffp.library\n");
  60. }
  61.