home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-bin.lha / lib / g++-include / builtin.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  3KB  |  126 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <cmath>
  34.  
  35. #ifndef __GNUC__
  36. #define __attribute__(x)
  37. #endif
  38.  
  39. typedef void (*one_arg_error_handler_t)(const char*);
  40. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  41.  
  42. long         gcd(long, long);
  43. long         lg(unsigned long); 
  44. double       pow(double, long);
  45. long         pow(long, long);
  46.  
  47. extern "C" double       start_timer();
  48. extern "C" double       return_elapsed_time(double last_time = 0.0);
  49.  
  50. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  51.  
  52. unsigned int hashpjw(const char*);
  53. unsigned int multiplicativehash(int);
  54. unsigned int foldhash(double);
  55.  
  56. extern void default_one_arg_error_handler(const char*) __attribute__ ((noreturn));
  57. extern void default_two_arg_error_handler(const char*, const char*) __attribute__ ((noreturn));
  58.  
  59. extern two_arg_error_handler_t lib_error_handler;
  60.  
  61. extern two_arg_error_handler_t 
  62.        set_lib_error_handler(two_arg_error_handler_t f);
  63.  
  64.  
  65. #if !defined(IV)
  66.  
  67. inline short abs(short arg) 
  68. {
  69.   return (arg < 0)? -arg : arg;
  70. }
  71.  
  72. inline int sign(long arg)
  73. {
  74.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  75. }
  76.  
  77. inline int sign(double arg)
  78. {
  79.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  80. }
  81.  
  82. inline long sqr(long arg)
  83. {
  84.   return arg * arg;
  85. }
  86.  
  87. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  88. inline double sqr(double arg)
  89. {
  90.   return arg * arg;
  91. }
  92. #endif
  93.  
  94. inline int even(long arg)
  95. {
  96.   return !(arg & 1);
  97. }
  98.  
  99. inline int odd(long arg)
  100. {
  101.   return (arg & 1);
  102. }
  103.  
  104. inline long lcm(long x, long y)
  105. {
  106.   return x / gcd(x, y) * y;
  107. }
  108.  
  109. inline void (setbit)(long& x, long b)
  110. {
  111.   x |= (1 << b);
  112. }
  113.  
  114. inline void clearbit(long& x, long b)
  115. {
  116.   x &= ~(1 << b);
  117. }
  118.  
  119. inline int testbit(long x, long b)
  120. {
  121.   return ((x & (1 << b)) != 0);
  122. }
  123.  
  124. #endif
  125. #endif
  126.