home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 213a.lha / Sozobon-C / libfp / _fpdiv.c next >
Text File  |  1996-02-14  |  1KB  |  46 lines

  1. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. long
  13. fpdiv(a,b)
  14. long a,b;
  15. {
  16.     long binv, adj;
  17.     long fpinv(), fpmul(), fpsub();
  18.  
  19.     binv = fpinv(b);
  20.     adj = fpmul(b,binv);
  21.     adj = fpsub(2.0,adj);
  22.     return fpmul(fpmul(a,binv),adj);
  23. }
  24.  
  25. fpinv(x)
  26. register long x;    /* d4 */
  27. {
  28.     int exp, sign;
  29.  
  30.     exp = x & 0x7f;
  31.     sign = x & 0x80;
  32.  
  33.     exp = 0x81 - exp;
  34.     if (exp > 0x7f)
  35.         return 0xffffff7f|sign;
  36.  
  37.     asm( "swap d4"            );
  38.     asm( "move.l #$7fffffff,d0"    );
  39.     asm( "divu d4,d0"        );
  40.     asm( "move.l d0,d4"        );
  41.     asm( "swap d4"            );
  42.     asm( "clr.w d4"            );
  43.  
  44.     return x|sign|exp;
  45. }
  46.