Operators with std::string
[libacl.git] / src / builtin.h
1 // This may look like C code, but it is really -*- C++ -*-
2
3 /* 
4 Copyright (C) 1988, 1992 Free Software Foundation
5     written by Doug Lea (dl@rocky.oswego.edu)
6
7 This file is part of the GNU C++ Library.  This library is free
8 software; you can redistribute it and/or modify it under the terms of
9 the GNU Library General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your
11 option) any later version.  This library is distributed in the hope
12 that it will be useful, but WITHOUT ANY WARRANTY; without even the
13 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE.  See the GNU Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /*
21   arithmetic, etc. functions on built in types
22 */
23
24
25 #ifndef _builtin_h
26 #define _builtin_h 1
27
28 //#include <_G_config.h>
29 #include <stddef.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <memory.h>
33 #include <unistd.h>
34 #include <stdio.h> 
35 #include <errno.h>
36 #include <fcntl.h>
37
38 #include <math.h>
39
40 #ifdef __GNUG__
41 #define _VOLATILE_VOID volatile void
42 #else
43 #define _VOLATILE_VOID void
44 #endif
45
46 typedef void (*one_arg_error_handler_t)(const char*);
47 typedef void (*two_arg_error_handler_t)(const char*, const char*);
48
49 long         gcd(long, long);
50 long         lg(unsigned long); 
51 double       pow(double, long);
52 long         pow(long, long);
53
54 double       start_timer();
55 double       return_elapsed_time(double last_time = 0.0);
56
57 char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
58
59 char*        chr(char ch, int width = 0);
60 char*        str(const char* s, int width = 0);
61
62 unsigned int hashpjw(const char*);
63 unsigned int multiplicativehash(int);
64 unsigned int foldhash(double);
65
66 extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
67 extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
68
69 extern two_arg_error_handler_t 
70        set_lib_error_handler(two_arg_error_handler_t f);
71
72
73 int sign(long arg);
74 int sign(double arg);
75 long sqr(long arg);
76 double sqr(double arg);
77 int even(long arg);
78 int odd(long arg);
79 long lcm(long x, long y);
80 void (setbit)(long& x, long b);
81 void clearbit(long& x, long b);
82 int testbit(long x, long b);
83
84 #if !defined(IV)
85
86 inline int sign(long arg)
87 {
88   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
89 }
90
91 inline int sign(double arg)
92 {
93   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
94 }
95
96 inline long sqr(long arg)
97 {
98   return arg * arg;
99 }
100
101 #ifndef __hpux /* hpux defines this in math.h */
102 inline double sqr(double arg)
103 {
104   return arg * arg;
105 }
106 #endif
107
108 inline int even(long arg)
109 {
110   return !(arg & 1);
111 }
112
113 inline int odd(long arg)
114 {
115   return (arg & 1);
116 }
117
118 inline long lcm(long x, long y)
119 {
120   return x / gcd(x, y) * y;
121 }
122
123 inline void (setbit)(long& x, long b)
124 {
125   x |= (1 << b);
126 }
127
128 inline void clearbit(long& x, long b)
129 {
130   x &= ~(1 << b);
131 }
132
133 inline int testbit(long x, long b)
134 {
135   return ((x & (1 << b)) != 0);
136 }
137
138 #endif
139 #endif