1 /***************************************************************************/
5 /* Arithmetic computations (specification). */
7 /* Copyright 1996-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
24 #include FT_FREETYPE_H
30 /* OLD 64-bits internal API */
32 #ifdef FT_CONFIG_OPTION_OLD_CALCS
36 typedef FT_INT64 FT_Int64;
38 #define ADD_64( x, y, z ) z = (x) + (y)
39 #define MUL_64( x, y, z ) z = (FT_Int64)(x) * (y)
40 #define DIV_64( x, y ) ( (x) / (y) )
42 #define SQRT_64( z ) FT_Sqrt64( z )
45 /*************************************************************************/
51 /* Computes the square root of a 64-bit value. That sounds stupid, */
52 /* but it is needed to obtain maximal accuracy in the TrueType */
53 /* bytecode interpreter. */
56 /* l :: A 64-bit integer. */
59 /* The 32-bit square-root. */
62 FT_Sqrt64( FT_Int64 l );
65 #else /* !FT_LONG64 */
68 typedef struct FT_Int64_
76 #define ADD_64( x, y, z ) FT_Add64( &x, &y, &z )
77 #define MUL_64( x, y, z ) FT_MulTo64( x, y, &z )
78 #define DIV_64( x, y ) FT_Div64by32( &x, y )
81 /*************************************************************************/
87 /* Add two Int64 values. */
90 /* x :: A pointer to the first value to be added. */
91 /* y :: A pointer to the second value to be added. */
94 /* z :: A pointer to the result of `x + y'. */
97 /* Will be wrapped by the ADD_64() macro. */
100 FT_Add64( FT_Int64* x,
105 /*************************************************************************/
111 /* Multiplies two Int32 integers. Returns an Int64 integer. */
114 /* x :: The first multiplier. */
115 /* y :: The second multiplier. */
118 /* z :: A pointer to the result of `x * y'. */
121 /* Will be wrapped by the MUL_64() macro. */
124 FT_MulTo64( FT_Int32 x,
129 /*************************************************************************/
135 /* Divides an Int64 value by an Int32 value. Returns an Int32 */
139 /* x :: A pointer to the dividend. */
140 /* y :: The divisor. */
143 /* The result of `x / y'. */
146 /* Will be wrapped by the DIV_64() macro. */
148 FT_EXPORT( FT_Int32 )
149 FT_Div64by32( FT_Int64* x,
153 #define SQRT_64( z ) FT_Sqrt64( &z )
156 /*************************************************************************/
162 /* Computes the square root of a 64-bits value. That sounds stupid, */
163 /* but it is needed to obtain maximal accuracy in the TrueType */
164 /* bytecode interpreter. */
167 /* z :: A pointer to a 64-bit integer. */
170 /* The 32-bit square-root. */
172 FT_EXPORT( FT_Int32 )
173 FT_Sqrt64( FT_Int64* x );
176 #endif /* !FT_LONG64 */
178 #endif /* FT_CONFIG_OPTION_OLD_CALCS */
182 FT_EXPORT( FT_Int32 ) FT_SqrtFixed( FT_Int32 x );
185 #ifndef FT_CONFIG_OPTION_OLD_CALCS
187 #define SQRT_32( x ) FT_Sqrt32( x )
190 /*************************************************************************/
196 /* Computes the square root of an Int32 integer (which will be */
197 /* handled as an unsigned long value). */
200 /* x :: The value to compute the root for. */
203 /* The result of `sqrt(x)'. */
205 FT_EXPORT( FT_Int32 )
206 FT_Sqrt32( FT_Int32 x );
209 #endif /* !FT_CONFIG_OPTION_OLD_CALCS */
212 /*************************************************************************/
214 /* FT_MulDiv() and FT_MulFix() are declared in freetype.h. */
216 /*************************************************************************/
219 #define INT_TO_F26DOT6( x ) ( (FT_Long)(x) << 6 )
220 #define INT_TO_F2DOT14( x ) ( (FT_Long)(x) << 14 )
221 #define INT_TO_FIXED( x ) ( (FT_Long)(x) << 16 )
222 #define F2DOT14_TO_FIXED( x ) ( (FT_Long)(x) << 2 )
223 #define FLOAT_TO_FIXED( x ) ( (FT_Long)( x * 65536.0 ) )
225 #define ROUND_F26DOT6( x ) ( x >= 0 ? ( ( (x) + 32 ) & -64 ) \
226 : ( -( ( 32 - (x) ) & -64 ) ) )
231 #endif /* __FTCALC_H__ */