You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
1.7 KiB

11 years ago
11 years ago
11 years ago
  1. package common
  2. func MaxInt8(a, b int8) int8 {
  3. if a > b {
  4. return a
  5. }
  6. return b
  7. }
  8. func MaxUint8(a, b uint8) uint8 {
  9. if a > b {
  10. return a
  11. }
  12. return b
  13. }
  14. func MaxInt16(a, b int16) int16 {
  15. if a > b {
  16. return a
  17. }
  18. return b
  19. }
  20. func MaxUint16(a, b uint16) uint16 {
  21. if a > b {
  22. return a
  23. }
  24. return b
  25. }
  26. func MaxInt32(a, b int32) int32 {
  27. if a > b {
  28. return a
  29. }
  30. return b
  31. }
  32. func MaxUint32(a, b uint32) uint32 {
  33. if a > b {
  34. return a
  35. }
  36. return b
  37. }
  38. func MaxInt64(a, b int64) int64 {
  39. if a > b {
  40. return a
  41. }
  42. return b
  43. }
  44. func MaxUint64(a, b uint64) uint64 {
  45. if a > b {
  46. return a
  47. }
  48. return b
  49. }
  50. func MaxInt(a, b int) int {
  51. if a > b {
  52. return a
  53. }
  54. return b
  55. }
  56. func MaxUint(a, b uint) uint {
  57. if a > b {
  58. return a
  59. }
  60. return b
  61. }
  62. //-----------------------------------------------------------------------------
  63. func MinInt8(a, b int8) int8 {
  64. if a < b {
  65. return a
  66. }
  67. return b
  68. }
  69. func MinUint8(a, b uint8) uint8 {
  70. if a < b {
  71. return a
  72. }
  73. return b
  74. }
  75. func MinInt16(a, b int16) int16 {
  76. if a < b {
  77. return a
  78. }
  79. return b
  80. }
  81. func MinUint16(a, b uint16) uint16 {
  82. if a < b {
  83. return a
  84. }
  85. return b
  86. }
  87. func MinInt32(a, b int32) int32 {
  88. if a < b {
  89. return a
  90. }
  91. return b
  92. }
  93. func MinUint32(a, b uint32) uint32 {
  94. if a < b {
  95. return a
  96. }
  97. return b
  98. }
  99. func MinInt64(a, b int64) int64 {
  100. if a < b {
  101. return a
  102. }
  103. return b
  104. }
  105. func MinUint64(a, b uint64) uint64 {
  106. if a < b {
  107. return a
  108. }
  109. return b
  110. }
  111. func MinInt(a, b int) int {
  112. if a < b {
  113. return a
  114. }
  115. return b
  116. }
  117. func MinUint(a, b uint) uint {
  118. if a < b {
  119. return a
  120. }
  121. return b
  122. }
  123. //-----------------------------------------------------------------------------
  124. func ExpUint64(a, b uint64) uint64 {
  125. accum := uint64(1)
  126. for b > 0 {
  127. if b&1 == 1 {
  128. accum *= a
  129. }
  130. a *= a
  131. b >>= 1
  132. }
  133. return accum
  134. }