home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / math / ffpconv.c < prev   
C/C++ Source or Header  |  1980-02-04  |  4KB  |  97 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* FFPConv.c
  23.  * Compiled with Lattice C 5.04: LC -b1 -cfist -ffs -v -y
  24.  * Linkage: c.o+FFPConv.o TO FFPConv Library lib:lcmffp.lib+lib:lc.lib+lib:amiga.lib
  25.  */
  26.  
  27. #include <exec/types.h>
  28. #include <libraries/mathffp.h>
  29. #ifdef LATTICE
  30. #include <stdio.h>
  31. #include <proto/all.h>
  32. #endif
  33.  
  34. struct Library *MathBase;
  35.  
  36. UBYTE st1[80] = "3.1415926535897";
  37. UBYTE st2[80] = "2.718281828459045";
  38. UBYTE st3[80], st4[80];
  39.  
  40. VOID main() {
  41.     
  42.     FLOAT num1, num2;
  43.     FLOAT n1, n2, n3, n4;
  44.     LONG  exp1, exp2, exp3, exp4;
  45.     LONG  mant1, mant2, mant3, mant4;
  46.     LONG  place1, place2;
  47.  
  48.     if((MathBase = OpenLibrary("mathffp.library", 0)) == 0) {
  49.         printf("Can't open mathffp.library\n");
  50.         exit(20);
  51.     }
  52.  
  53.  
  54.     n1 = afp(st1);            /* Call afp entry */
  55.     n2 = afp(st2);            /* Call afp entry */
  56.     printf("\n\nASCII %s converts to floating point %f",
  57.         st1, n1);
  58.     printf("\nASCII %s converts to floating point %f",
  59.         st2, n2);
  60.  
  61.     num1 = 3.1415926535897;
  62.     num2 = 2.718281828459045;
  63.  
  64.     exp1 = fpa(num1, st3);    /* Call fpa entry */
  65.     exp2 = fpa(num2, st4);    /* Call fpa entry */
  66.     printf("\n\nfloating point %f converts to ASCII %s", num1, st3);
  67.     printf("\nfloating point %f converts to ASCII %s",
  68.         num2, st4);
  69.  
  70.     place1 = -2;
  71.     place2 = -1;
  72.     arnd(place1, exp1, st3);    /* Call arnd entry */
  73.     arnd(place2, exp2, st4);    /* Call arnd entry */
  74.     printf("\nASCII round of %f to %d places yields %s",
  75.         num1, place1, st3);
  76.     printf("\nASCII round of %f to %d places yields %s",
  77.         num2, place2, st4);
  78.  
  79.     exp1  = -3;   exp2  = 3;    exp3  = -3;   exp4  = 3;
  80.     mant1 = 12345;  mant2 = -54321;  mant3 = -12345; mant4 = 54321;
  81.  
  82.     n1 = dbf(exp1, mant1);        /* Call dbf entry */
  83.     n2 = dbf(exp2, mant2);        /* Call dbf entry */
  84.     n3 = dbf(exp3, mant3);        /* Call dbf entry */
  85.     n4 = dbf(exp4, mant4);        /* Call dbf entry */
  86.     printf("\n\ndbf of exp = %d and mant = %d yields FFP number of %f",
  87.            exp1, mant1, n1);
  88.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f",
  89.            exp2, mant2, n2);
  90.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f",
  91.            exp3, mant3, n3);
  92.     printf("\ndbf of exp = %d and mant = %d yields FFP number of %f",
  93.            exp4, mant4, n4);
  94.  
  95.     CloseLibrary(MathBase);
  96. }
  97.