home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / g++ / builtin.h < prev    next >
C/C++ Source or Header  |  1993-06-29  |  3KB  |  163 lines

  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. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _builtin_h 1
  30.  
  31. #include <stddef.h>
  32. #include <std.h>
  33. #include <math.h>
  34.  
  35. #ifdef __GNUG__
  36. #define _VOLATILE_VOID volatile void
  37. #else
  38. #define _VOLATILE_VOID void
  39. #endif
  40.  
  41. typedef void (*one_arg_error_handler_t)(const char*);
  42. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  43.  
  44. long         gcd(long, long);
  45. long         lg(unsigned long); 
  46. double       pow(double, long);
  47. long         pow(long, long);
  48.  
  49. double       start_timer();
  50. double       return_elapsed_time(double last_time = 0.0);
  51.  
  52. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  53.  
  54. char*        chr(char ch, int width = 0);
  55. char*        str(const char* s, int width = 0);
  56.  
  57. unsigned int hashpjw(const char*);
  58. unsigned int multiplicativehash(int);
  59. unsigned int foldhash(double);
  60.  
  61. extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
  62. extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
  63.  
  64. extern two_arg_error_handler_t lib_error_handler;
  65.  
  66. extern two_arg_error_handler_t 
  67.        set_lib_error_handler(two_arg_error_handler_t f);
  68.  
  69.  
  70. double abs(double arg);
  71. float abs(float arg);
  72. short abs(short arg);
  73. long abs(long arg);
  74. int sign(long arg);
  75. int sign(double arg);
  76. long sqr(long arg);
  77. double sqr(double arg);
  78. int even(long arg);
  79. int odd(long arg);
  80. long lcm(long x, long y);
  81. void (setbit)(long& x, long b);
  82. void clearbit(long& x, long b);
  83. int testbit(long x, long b);
  84.  
  85. #if !defined(IV)
  86.  
  87. #ifndef __hpux /* hpux defines this in math.h */
  88. inline double abs(double arg) 
  89. {
  90.   return (arg < 0.0)? -arg : arg;
  91. }
  92. #endif
  93.  
  94. inline float abs(float arg) 
  95. {
  96.   return (arg < 0.0)? -arg : arg;
  97. }
  98.  
  99. inline short abs(short arg) 
  100. {
  101.   return (arg < 0)? -arg : arg;
  102. }
  103.  
  104. inline long abs(long arg) 
  105. {
  106.   return (arg < 0)? -arg : arg;
  107. }
  108.  
  109. inline int sign(long arg)
  110. {
  111.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  112. }
  113.  
  114. inline int sign(double arg)
  115. {
  116.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  117. }
  118.  
  119. inline long sqr(long arg)
  120. {
  121.   return arg * arg;
  122. }
  123.  
  124. #ifndef __hpux /* hpux defines this in math.h */
  125. inline double sqr(double arg)
  126. {
  127.   return arg * arg;
  128. }
  129. #endif
  130.  
  131. inline int even(long arg)
  132. {
  133.   return !(arg & 1);
  134. }
  135.  
  136. inline int odd(long arg)
  137. {
  138.   return (arg & 1);
  139. }
  140.  
  141. inline long lcm(long x, long y)
  142. {
  143.   return x / gcd(x, y) * y;
  144. }
  145.  
  146. inline void (setbit)(long& x, long b)
  147. {
  148.   x |= (1 << b);
  149. }
  150.  
  151. inline void clearbit(long& x, long b)
  152. {
  153.   x &= ~(1 << b);
  154. }
  155.  
  156. inline int testbit(long x, long b)
  157. {
  158.   return ((x & (1 << b)) != 0);
  159. }
  160.  
  161. #endif
  162. #endif
  163.