home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / builtin.h < prev    next >
C/C++ Source or Header  |  1993-07-23  |  3KB  |  157 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1988 Free Software Foundation
  5.     written by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of GNU CC.
  8.  
  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.
  15.  
  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.  
  23. */
  24.  
  25. /*
  26.   arithmetic, etc. functions on built in types
  27. */
  28.  
  29.  
  30. #ifndef _builtin_h
  31. #pragma once
  32. #define _builtin_h 1
  33.  
  34. overload clearbit;
  35. overload dec;
  36. overload gcd;
  37. overload hex;
  38. overload lcm;
  39. overload lg;
  40. overload oct;
  41. overload setbit;
  42. overload sign;
  43. overload sqr;
  44. overload testbit;
  45. overload even;
  46. overload odd;
  47.  
  48. #include <std.h>
  49. #include <stddef.h>
  50. #include <math.h>
  51.  
  52. long         abs(long);
  53. double       abs(double);
  54. void         clearbit(long&, long);
  55. void         setbit(long&, long);
  56. int          testbit(long, long);
  57. int          even(long);
  58. long         gcd(long, long);
  59. long         lg(long); 
  60. long         lcm(long, long);
  61. int          odd(long);
  62. double       pow(double, long);
  63. long         pow(long, long);
  64. int          sign(long);
  65. int          sign(double);
  66. long         sqr(long);
  67. double       sqr(double);
  68. long         sqrt(long);
  69.  
  70. double       start_timer();
  71. double       return_elapsed_time(double);
  72.  
  73. char*        itoa(long x, int base = 10, int width = 0);
  74. char*        hex(long x, int width = 0);
  75. char*        oct(long x, int width = 0);
  76. char*        dec(long x, int width = 0);
  77. char*        form(const char* fmt ...);
  78. char*        chr(char ch);
  79.  
  80. unsigned int hashpjw(const char*);
  81. unsigned int multiplicativehash(int);
  82. unsigned int foldhash(double);
  83.  
  84. extern void default_one_arg_error_handler(const char*);
  85. extern void default_two_arg_error_handler(const char*, const char*);
  86.  
  87. extern two_arg_error_handler_t lib_error_handler;
  88.  
  89. extern two_arg_error_handler_t 
  90.        set_lib_error_handler(two_arg_error_handler_t f);
  91.  
  92. //#ifdef __OPTIMIZE__
  93.  
  94. inline double abs(double _arg) 
  95. {
  96.   return (_arg < 0.0)? -_arg : _arg;
  97. }
  98.  
  99. inline long abs(long _arg) 
  100. {
  101.   return (_arg < 0)? -_arg : _arg;
  102. }
  103.  
  104. inline int sign(long _arg)
  105. {
  106.   return (_arg == 0) ? 0 : ( (_arg > 0) ? 1 : -1 );
  107. }
  108.  
  109. inline int sign(double _arg)
  110. {
  111.   return (_arg == 0.0) ? 0 : ( (_arg > 0.0) ? 1 : -1 );
  112. }
  113.  
  114. inline long sqr(long _arg)
  115. {
  116.   return _arg * _arg;
  117. }
  118.  
  119. inline double sqr(double _arg)
  120. {
  121.   return _arg * _arg;
  122. }
  123.  
  124. inline int even(long _arg)
  125. {
  126.   return !(_arg & 1);
  127. }
  128.  
  129. inline int odd(long _arg)
  130. {
  131.   return (_arg & 1);
  132. }
  133.  
  134. inline long lcm(long _x, long _y)
  135. {
  136.   return _x / gcd(_x, _y) * _y;
  137. }
  138.  
  139. inline void setbit(long& _x, long _b)
  140. {
  141.   _x |= (1 << _b);
  142. }
  143.  
  144. inline void clearbit(long& _x, long _b)
  145. {
  146.   _x &= ~(1 << _b);
  147. }
  148.  
  149. inline int testbit(long _x, long _b)
  150. {
  151.   return ((_x & (1 << _b)) != 0);
  152. }
  153.  
  154. //#endif
  155.  
  156. #endif
  157.