xref: /plan9/sys/src/cmd/gs/src/math_.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1989, 1995, 1998, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: math_.h,v 1.7 2004/04/08 16:18:25 giles Exp $ */
18 /* Generic substitute for math.h */
19 
20 #ifndef math__INCLUDED
21 #  define math__INCLUDED
22 
23 /* We must include std.h before any file that includes sys/types.h. */
24 #include "std.h"
25 
26 #if defined(VMS) && defined(__GNUC__)
27 /*  DEC VAX/VMS C comes with a math.h file, but GNU VAX/VMS C does not. */
28 #  include "vmsmath.h"
29 #else
30 #  include <math.h>
31 #endif
32 
33 /* math.h is different for Turbo and Unix.... */
34 #ifndef M_PI
35 #  ifdef PI
36 #    define M_PI PI
37 #  else
38 #    define M_PI 3.14159265358979324
39 #  endif
40 #endif
41 
42 /* Factors for converting between degrees and radians */
43 #define degrees_to_radians (M_PI / 180.0)
44 #define radians_to_degrees (180.0 / M_PI)
45 
46 /*
47  * Define the maximum value of a single-precision float.
48  * This doesn't seem to be defined in any standard place,
49  * and we need an exact value for it.
50  */
51 #undef MAX_FLOAT		/* just in case */
52 #if defined(vax) || defined(VAX) || defined(__vax) || defined(__VAX)
53 /* Maximum exponent is +127, 23 bits of fraction. */
54 #  define MAX_FLOAT\
55      ((0x800000 - 1.0) * 0x1000000 * 0x1000000 * 0x10000000 * 0x10000000)
56 #else
57 /* IEEE, maximum exponent is +127, 23 bits of fraction + an implied '1'. */
58 #  define MAX_FLOAT\
59      ((0x1000000 - 1.0) * 0x1000000 * 0x1000000 * 0x10000000 * 0x10000000)
60 #endif
61 
62 /* Define the hypot procedure on those few systems that don't provide it. */
63 #if defined(_IBMR2)
64 /* The RS/6000 has hypot, but math.h doesn't declare it! */
65 extern double hypot(double, double);
66 #elif defined(_MSC_VER)
67 #  define hypot(x,y) _hypot(x,y)
68 #elif !defined(__TURBOC__) && !defined(BSD4_2) && !defined(VMS) && !defined(__MWERKS__) && !defined(HAVE_HYPOT)
69 #  define hypot(x,y) sqrt((double)(x)*(x)+(double)(y)*(y))
70 #endif
71 
72 #ifdef OSK
73 /* OSK has atan2 and ldexp, but math.h doesn't declare them! */
74 extern double atan2(), ldexp();
75 #endif
76 
77 /* Intercept calls on sqrt for debugging. */
78 extern double gs_sqrt(double, const char *, int);
79 #ifdef DEBUG
80 #undef sqrt
81 #define sqrt(x) gs_sqrt(x, __FILE__, __LINE__)
82 #endif /* DEBUG */
83 
84 #endif /* math__INCLUDED */
85