home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXARITH.H < prev    next >
Text File  |  1994-07-27  |  3KB  |  61 lines

  1. /* Copyright (C) 1990, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxarith.h */
  20. /* Arithmetic macros for Ghostscript library */
  21.  
  22. /* Define an in-line abs function, good for any signed numeric type. */
  23. #define any_abs(x) ((x) < 0 ? -(x) : (x))
  24.  
  25. /* Test whether an integral value fits in a given number of bits. */
  26. /* This works for all integral types. */
  27. #define fits_in_bits(i, n)\
  28.   (sizeof(i) <= sizeof(int) ? fits_in_ubits((i) + (1 << ((n) - 1)), (n) + 1) :\
  29.    fits_in_ubits((i) + (1L << ((n) - 1)), (n) + 1))
  30. #define fits_in_ubits(i, n) (((i) >> (n)) == 0)
  31.  
  32. /* Test floating point values against constants. */
  33. /* gxfarith.h redefines these on machines with very slow floating point. */
  34. /* Only use these macros on variables, not on expressions. */
  35. #define is_fzero(f) ((f) == 0.0)
  36. #define is_fzero2(f1,f2) ((f1) == 0.0 && (f2) == 0.0)
  37. #define is_fneg(f) ((f) < 0.0)
  38. #define is_fge1(f) ((f) >= 1.0)
  39. #define is_fposbits(f, n)\
  40.   ((f) >= 0 && (f) < 4.0 * (1L << ((n) - 2)))
  41. #define is_fbits(f, n)\
  42.   ((f) >= -4.0 * (1L << ((n) - 2)) && (f) < 4.0 * (1L << ((n) - 2)))
  43.  
  44. /*
  45.  * Define a macro for computing log2(n), where n=1,2,4,...,128.
  46.  * Because some compilers limit the total size of a statement,
  47.  * this macro must only mention n once.  The macro should really
  48.  * only be used with compile-time constant arguments, but it will work
  49.  * even if n is an expression computed at run-time.
  50.  */
  51. #define small_exact_log2(n)\
  52.  ((uint)(05637042010L >> ((((n) % 11) - 1) * 3)) & 7)
  53.  
  54. /*
  55.  * The following doesn't give rise to a macro, but is used in several
  56.  * places in Ghostscript.  We observe that if M = 2^n-1 and V < M^2,
  57.  * then the quotient Q and remainder R can be computed as:
  58.  *        Q = V / M = (V + (V >> n) + 1) >> n;
  59.  *        R = V % M = (V + (V / M)) & M = V - (Q << n) + Q.
  60.  */
  61.