home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXFARITH.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  3KB  |  86 lines

  1. /* Copyright (C) 1993 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. /* gxfarith.h */
  20. /* Floating point arithmetic macros for Ghostscript library */
  21. #include "gxarith.h"
  22.  
  23. /*
  24.  * These macros replace the ones in gxarith.h on machines
  25.  * that are likely to have very slow floating point.
  26.  * Note that any module that includes this file should be compiled
  27.  * with USE_FPU defined; otherwise, the default definitions will prevail.
  28.  */
  29. #ifdef USE_FPU
  30. # if USE_FPU <= 0 && arch_floats_are_IEEE && (arch_sizeof_float == arch_sizeof_int || arch_sizeof_float == arch_sizeof_long)
  31. #  if arch_sizeof_float == arch_sizeof_int
  32. #    define _f_as_int(f) *(int *)(&(f))
  33. #  else        /* arch_sizeof_float == arch_sizeof_long */
  34. #    define _f_as_int(f) *(long *)(&(f))
  35. #  endif
  36. #  if arch_sizeof_double == arch_sizeof_int
  37. #    define _d_as_int(f) *(int *)(&(d))
  38. #  else
  39. #   if arch_sizeof_double == arch_sizeof_long
  40. #    define _d_as_int(f) *(long *)(&(d))
  41. #   endif
  42. #  endif
  43. #  ifdef _d_as_int
  44. #    define _fdtest(v,f,d,n)\
  45.     (sizeof(v)==sizeof(float)?(f):sizeof(v)==sizeof(double)?(d):(n))
  46. #  else
  47. #    define _fdtest(v,f,d,n)\
  48.     (sizeof(v)==sizeof(float)?(f):(n))
  49. #  endif
  50. #  undef is_fzero
  51. #  define is_fzero(f)    /* must handle both +0 and -0 */\
  52.      _fdtest(f, (_f_as_int(f) << 1) == 0, (_d_as_int(f) << 1) == 0,\
  53.        (f) == 0.0)
  54. #  undef is_fzero2
  55. #  define is_fzero2(f1,f2)\
  56.      (sizeof(f1) == sizeof(float) && sizeof(f2) == sizeof(float) ?\
  57.       ((_f_as_int(f1) | _f_as_int(f2)) << 1) == 0 :\
  58.       (f1) == 0.0 && (f2) == 0.0)
  59. #  undef is_fneg
  60. #  if arch_is_big_endian
  61. #    define _is_fnegb(f) (*(byte *)&(f) >= 0x80)
  62. #  else
  63. #    define _is_fnegb(f) (((byte *)&(f))[sizeof(f) - 1] >= 0x80)
  64. #  endif
  65. #  if arch_sizeof_float == arch_sizeof_int
  66. #    define is_fneg(f)\
  67.        (sizeof(f) == sizeof(float) ? _f_as_int(f) < 0 :\
  68.     _is_fnegb(f))
  69. #  else
  70. #    define is_fneg(f) _is_fnegb(f)
  71. #  endif
  72. #  undef is_fge1
  73. #  if arch_sizeof_float == arch_sizeof_int
  74. #    define is_fge1(f)\
  75.        (sizeof(f) == sizeof(float) ?\
  76.     (_f_as_int(f)) >= 0x3f800000 /* IEEE 1.0 */ :\
  77.     (f) >= 1.0)
  78. #  else            /* arch_sizeof_float == arch_sizeof_long */
  79. #    define is_fge1(f)\
  80.        (sizeof(f) == sizeof(float) ?\
  81.     (int)(_f_as_int(f) >> 16) >= 0x3f80 :\
  82.     (f) >= 1.0)
  83. #  endif
  84. # endif
  85. #endif
  86.