Sync usage with man page.
[netbsd-mini2440.git] / gnu / lib / libg++ / g++-include / builtin.h
blob904059b8af89418fd347e7868263db8ccdbc5eaf
1 // This may look like C code, but it is really -*- C++ -*-
3 /*
4 Copyright (C) 1988 Free Software Foundation
5 written by Doug Lea (dl@rocky.oswego.edu)
7 This file is part of GNU CC.
9 GNU CC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY. No author or distributor
11 accepts responsibility to anyone for the consequences of using it
12 or for whether it serves any particular purpose or works at all,
13 unless he says so in writing. Refer to the GNU CC General Public
14 License for full details.
16 Everyone is granted permission to copy, modify and redistribute
17 GNU CC, but only under the conditions described in the
18 GNU CC General Public License. A copy of this license is
19 supposed to have been given to you along with GNU CC so you
20 can know your rights and responsibilities. It should be in a
21 file named COPYING. Among other things, the copyright notice
22 and this notice must be preserved on all copies.
26 arithmetic, etc. functions on built in types
30 #ifndef _builtin_h
31 #ifdef __GNUG__
32 #pragma once
33 #pragma interface
34 #endif
35 #define _builtin_h 1
38 typedef void (*one_arg_error_handler_t)(const char*);
39 typedef void (*two_arg_error_handler_t)(const char*, const char*);
43 #include <stddef.h>
44 #include <std.h>
45 #include <math.h>
47 long gcd(long, long);
48 long lg(unsigned long);
49 double pow(double, long);
50 long pow(long, long);
52 double start_timer();
53 double return_elapsed_time(double last_time = 0.0);
55 char* itoa(long x, int base = 10, int width = 0);
56 char* itoa(unsigned long x, int base = 10, int width = 0);
57 #ifdef __GNUG__
58 char* itoa(long long x, int base = 10, int width = 0);
59 char* itoa(unsigned long long x, int base = 10, int width = 0);
60 #endif
61 char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
63 char* hex(long x, int width = 0);
64 char* hex(unsigned long x, int width = 0);
65 char* hex(int x, int width = 0);
66 char* hex(short x, int width = 0);
67 char* hex(unsigned int x, int width = 0);
68 char* hex(unsigned short x, int width = 0);
70 char* oct(long x, int width = 0);
71 char* oct(unsigned long x, int width = 0);
72 char* oct(int x, int width = 0);
73 char* oct(short x, int width = 0);
74 char* oct(unsigned int x, int width = 0) ;
75 char* oct(unsigned short x, int width = 0);
77 char* dec(long x, int width = 0);
78 char* dec(unsigned long x, int width = 0);
79 char* dec(int x, int width = 0);
80 char* dec(short x, int width = 0);
81 char* dec(unsigned int x, int width = 0) ;
82 char* dec(unsigned short x, int width = 0);
84 char* form(const char* fmt ...);
85 char* chr(char ch, int width = 0);
86 char* str(const char* s, int width = 0);
88 unsigned int hashpjw(const char*);
89 unsigned int multiplicativehash(int);
90 unsigned int foldhash(double);
92 extern void default_one_arg_error_handler(const char*);
93 extern void default_two_arg_error_handler(const char*, const char*);
95 extern two_arg_error_handler_t lib_error_handler;
97 extern two_arg_error_handler_t
98 set_lib_error_handler(two_arg_error_handler_t f);
101 double abs(double arg);
102 float abs(float arg);
103 short abs(short arg);
104 long abs(long arg);
105 int sign(long arg);
106 int sign(double arg);
107 long sqr(long arg);
108 double sqr(double arg);
109 int even(long arg);
110 int odd(long arg);
111 long lcm(long x, long y);
112 void setbit(long& x, long b);
113 void clearbit(long& x, long b);
114 int testbit(long x, long b);
116 signed char min(signed char a, signed char b);
117 unsigned char min(unsigned char a, unsigned char b);
119 signed short min(signed short a, signed short b);
120 unsigned short min(unsigned short a, unsigned short b);
122 signed int min(signed int a, signed int b);
123 unsigned int min(unsigned int a, unsigned int b);
125 signed long min(signed long a, signed long b);
126 unsigned long min(unsigned long a, unsigned long b);
128 float min(float a, float b);
130 double min(double a, double b);
132 signed char max(signed char a, signed char b);
133 unsigned char max(unsigned char a, unsigned char b);
135 signed short max(signed short a, signed short b);
136 unsigned short max(unsigned short a, unsigned short b);
138 signed int max(signed int a, signed int b);
139 unsigned int max(unsigned int a, unsigned int b);
141 signed long max(signed long a, signed long b);
142 unsigned long max(unsigned long a, unsigned long b);
144 float max(float a, float b);
146 double max(double a, double b);
148 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
151 inline double abs(double arg)
153 return (arg < 0.0)? -arg : arg;
156 inline float abs(float arg)
158 return (arg < 0.0)? -arg : arg;
161 inline short abs(short arg)
163 return (arg < 0)? -arg : arg;
166 inline long abs(long arg)
168 return (arg < 0)? -arg : arg;
171 inline int sign(long arg)
173 return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
176 inline int sign(double arg)
178 return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
181 inline long sqr(long arg)
183 return arg * arg;
186 inline double sqr(double arg)
188 return arg * arg;
191 inline int even(long arg)
193 return !(arg & 1);
196 inline int odd(long arg)
198 return (arg & 1);
201 inline long lcm(long x, long y)
203 return x / gcd(x, y) * y;
206 inline void setbit(long& x, long b)
208 x |= (1 << b);
211 inline void clearbit(long& x, long b)
213 x &= ~(1 << b);
216 inline int testbit(long x, long b)
218 return ((x & (1 << b)) != 0);
221 inline char* hex(int x, int width = 0) { return hex(long(x), width); }
222 inline char* hex(short x, int width = 0) { return hex(long(x), width); }
223 inline char* hex(unsigned int x, int width = 0)
224 { return hex((unsigned long)(x), width); }
225 inline char* hex(unsigned short x, int width = 0)
226 { return hex((unsigned long)(x), width); }
228 inline char* oct(int x, int width = 0) { return oct(long(x), width); }
229 inline char* oct(short x, int width = 0) { return oct(long(x), width); }
230 inline char* oct(unsigned int x, int width = 0)
231 { return oct((unsigned long)(x), width); }
232 inline char* oct(unsigned short x, int width = 0)
233 { return oct((unsigned long)(x), width); }
235 inline char* dec(int x, int width = 0) { return dec(long(x), width); }
236 inline char* dec(short x, int width = 0) { return dec(long(x), width); }
237 inline char* dec(unsigned int x, int width = 0)
238 { return dec((unsigned long)(x), width); }
239 inline char* dec(unsigned short x, int width = 0)
240 { return dec((unsigned long)(x), width); }
242 inline signed char min(signed char a, signed char b) { return (a < b)?a:b;}
243 inline unsigned char min(unsigned char a, unsigned char b) {return (a < b)?a:b;}
245 inline signed short min(signed short a, signed short b) {return (a < b) ?a:b;}
246 inline unsigned short min(unsigned short a, unsigned short b) {return (a < b)?a:b;}
248 inline signed int min(signed int a, signed int b) {return (a < b)?a:b;}
249 inline unsigned int min(unsigned int a, unsigned int b) {return (a < b)?a:b;}
251 inline signed long min(signed long a, signed long b) {return (a < b)?a:b;}
252 inline unsigned long min(unsigned long a, unsigned long b) {return (a < b)?a:b;}
254 inline float min(float a, float b) {return (a < b)?a:b;}
256 inline double min(double a, double b) {return (a < b)?a:b;}
258 inline signed char max(signed char a, signed char b) { return (a > b)?a:b;}
259 inline unsigned char max(unsigned char a, unsigned char b) {return (a > b)?a:b;}
261 inline signed short max(signed short a, signed short b) {return (a > b) ?a:b;}
262 inline unsigned short max(unsigned short a, unsigned short b) {return (a > b)?a:b;}
264 inline signed int max(signed int a, signed int b) {return (a > b)?a:b;}
265 inline unsigned int max(unsigned int a, unsigned int b) {return (a > b)?a:b;}
267 inline signed long max(signed long a, signed long b) {return (a > b)?a:b;}
268 inline unsigned long max(unsigned long a, unsigned long b) {return (a > b)?a:b;}
270 inline float max(float a, float b) {return (a > b)?a:b;}
272 inline double max(double a, double b) {return (a > b)?a:b;}
274 #endif
276 #endif