home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / SCALEWID.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  836b  |  24 lines

  1. /*
  2.  *   Code to scale dimensions.  Takes two thirty-two bit integers, multiplies
  3.  *   them, divides them by 2^20, and returns the thirty-two bit result.
  4.  *   The first integer, the width in FIXes, can lie between -2^24 and 2^24-1.
  5.  *   The second integer, the scale factor, can lie between 0 and 2^27-1.  The
  6.  *   arithmetic must be exact.  The answer is truncated to an integer.
  7.  *
  8.  *   Since this math is special, we put it in its own file.  It is the only
  9.  *   place in the program where such accuracy is required.
  10.  */
  11. #include "structures.h" /* The copyright notice in that file is included too! */
  12.  
  13. integer
  14. scalewidth(a, b)
  15.         register integer a, b ;
  16. {
  17.   register integer al, bl ;
  18.   al = a & 32767 ;
  19.   bl = b & 32767 ;
  20.   a >>= 15 ;
  21.   b >>= 15 ;
  22.   return ( ((al*bl/32768) + a*bl+al*b)/32 + a*b*1024) ;
  23. }
  24.