home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / ft-beta.zip / freetype / lib / ttcalc.h < prev    next >
C/C++ Source or Header  |  1997-10-06  |  4KB  |  156 lines

  1. /*******************************************************************
  2.  *
  3.  *  ttcalc.h
  4.  *
  5.  *    Arithmetic Computations (specification).
  6.  *
  7.  *  Copyright 1996, 1997 by
  8.  *  David Turner, Robert Wilhelm, and Werner Lemberg.
  9.  *
  10.  *  This file is part of the FreeType project, and may only be used
  11.  *  modified and distributed under the terms of the FreeType project
  12.  *  license, LICENSE.TXT. By continuing to use, modify or distribute 
  13.  *  this file you indicate that you have read the license and
  14.  *  understand and accept it fully.
  15.  *
  16.  *  Added support for 64-bit scalars.
  17.  *
  18.  ******************************************************************/
  19.  
  20. #ifndef TTCALC_H
  21. #define TTCALC_H
  22.  
  23. #include "ttcommon.h"
  24. #include "tttypes.h"
  25.  
  26.   /* IntN types :                                                       */
  27.   /*                                                                    */
  28.   /*   Used to guarantee the size of some specific integers.            */
  29.   /*                                                                    */
  30.   /*  Of course, they are equivalent to Short, UShort, Long, etc.       */
  31.   /*  but parts of this unit could be used by different programs.       */
  32.   /*                                                                    */
  33.  
  34.   typedef signed short    Int16;
  35.   typedef unsigned short  Word16;
  36.  
  37. #if SIZEOF_INT == 4
  38.  
  39.   typedef signed int      Int32;
  40.   typedef unsigned int    Word32;
  41.  
  42. #elif SIZEOF_LONG == 4
  43.  
  44.   typedef signed long     Int32;
  45.   typedef unsigned long   Word32;
  46.  
  47. #else
  48. #error "no 32bit type found"
  49. #endif
  50.  
  51. #if SIZEOF_LONG == 8
  52.  
  53. /* LONG64 must be defined when a 64-bit type is available */
  54. #define LONG64
  55. #define INT64   long
  56.  
  57. #else
  58. /* GCC provides the non-ANSI 'long long' 64-bit type. You can activate */
  59. /* by defining the _GNUC_LONG64_ macro in 'ttconfig.h'. Note that this */
  60. /* will produce many -ansi warnings during lib compiles..              */
  61. #ifdef _GNUC_LONG64_
  62.  
  63. #define LONG64
  64. #define INT64   long long
  65.  
  66. #endif /* __GNUC__ */
  67. #endif
  68.  
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72.  
  73. #ifdef LONG64
  74.  
  75.   typedef INT64  Int64;
  76.  
  77.   #define FMulDiv( x, y, z )        ( (Int64)(x) * (y) / (z) )
  78.   /* Fast muldiv */
  79.  
  80.   #define FMulDiv_Round( x, y, z )  ( ( (Int64)(x) * (y) + (z)/2 ) / (z) )
  81.   /* Fast muldiv_round */
  82.  
  83.   #define ADD_64( x, y, z )  z = x + y
  84.   #define SUB_64( x, y, z )  z = x - y
  85.   #define MUL_64( x, y, z )  z = (Int64)(x) * (y)
  86.  
  87.   #define DIV_64( x, y )     ( (x) / (y) )
  88.  
  89.   #define SQRT_64( x )       Sqrt64( x )
  90.   #define SQRT_32( x )       Sqrt32( x )
  91.  
  92.   Int32  MulDiv( Int32  a, Int32  b, Int32  c );
  93.   Int32  MulDiv_Round( Int32  a, Int32  b, Int32  c );
  94.  
  95.   Int32  Sqrt32( Int32  l );
  96.   Int32  Sqrt64( Int64  l );
  97.  
  98. #else
  99.  
  100.   struct _Int64
  101.   {
  102.     Word32  lo;
  103.     Word32  hi;
  104.   };
  105.   typedef struct _Int64   Int64;
  106.  
  107.   #define FMulDiv( x, y, z )        MulDiv( x, y, z )
  108.   #define FMulDiv_Round( x, y, z )  MulDiv_Round( x, y, z )
  109.  
  110.   #define ADD_64( x, y, z )  Add64( &x, &y, &z )
  111.   #define SUB_64( x, y, z )  Sub64( &x, &y, &z )
  112.   #define MUL_64( x, y, z )  MulTo64( x, y, &z )
  113.  
  114.   #define DIV_64( x, y )     Div64by32( &x, y )
  115.  
  116.   #define SQRT_64( x )       Sqrt64( &x )
  117.   #define SQRT_32( x )       Sqrt32( x )
  118.  
  119.   Int32  MulDiv( Int32  a, Int32  b, Int32  c );
  120.   Int32  MulDiv_Round( Int32  a, Int32  b, Int32  c );
  121.  
  122.   void  Add64( Int64*  x, Int64*  y, Int64*  z );
  123.   void  Sub64( Int64*  x, Int64*  y, Int64*  z );
  124.  
  125.   void  MulTo64( Int32  x, Int32  y, Int64*  z );
  126.  
  127.   Int32  Div64by32( Int64*  x, Int32  y );
  128.  
  129.   Int  Order64( Int64*  z );
  130.   Int  Order32( Int32   z );
  131.  
  132.   Int32  Sqrt32( Int32   l );
  133.   Int32  Sqrt64( Int64*  l );
  134.  
  135. #endif /* LONG64 */
  136.  
  137.  
  138. #define MUL_FIXED( a, b )      MulDiv_Round( (a), (b), 1 << 16 )
  139. #define INT_TO_F26DOT6( x )    ( (Long)(x) << 6  )
  140. #define INT_TO_F2DOT14( x )    ( (Long)(x) << 14 )
  141. #define INT_TO_FIXED( x )      ( (Long)(x) << 16 )
  142. #define F2DOT14_TO_FIXED( x )  ( (Long)(x) << 2  )
  143. #define FLOAT_TO_FIXED( x )    ( (Long)(x * 65536.0) )
  144.  
  145. #define ROUND_F26DOT6( x )     ( x >= 0 ? (   ((x) + 32) & -64) \
  146.                                         : ( -((32 - (x)) & -64) ) )
  147.  
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151.  
  152. #endif /* TTCALC_H */
  153.  
  154.  
  155. /* End */
  156.