Back to index

tetex-bin  3.0
scalewidth.c
Go to the documentation of this file.
00001 /*
00002  *   Code to scale dimensions.  Takes two thirty-two bit integers, multiplies
00003  *   them, divides them by 2^20, and returns the thirty-two bit result.
00004  *   The first integer, the width in FIXes, can lie between -2^24 and 2^24-1.
00005  *   The second integer, the scale factor, can lie between 0 and 2^27-1.
00006  *
00007  *   Here, unlike in TeX, we do the arithmetic exactly.  Since the error
00008  *   in the TeX arithmetic is parts per million, and since dvips makes no
00009  *   layout decisions, this has no effect.  (TeX stipulates that any
00010  *   implementation of *TeX* needs to do the arithmetic exactly as
00011  *   specified in TeX, but drivers need not.)
00012  *
00013  *   Since this math is special, we put it in its own file.  It is the only
00014  *   place in the program where such accuracy is required.
00015  */
00016 #include "dvips.h" /* The copyright notice in that file is included too! */
00017 
00018 integer
00019 scalewidth P2C(register integer, a, register integer, b)
00020 {
00021   register integer al, bl ;
00022 
00023   if (a < 0)
00024      return -scalewidth(-a, b) ;
00025   if (b < 0)
00026      return -scalewidth(a, -b) ;
00027   al = a & 32767 ;
00028   bl = b & 32767 ;
00029   a >>= 15 ;
00030   b >>= 15 ;
00031   return ( ((al*bl/32768) + a*bl+al*b)/32 + a*b*1024) ;
00032 }