IpUtils.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright (C) 2004, 2009 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpUtils.hpp 2167 2013-03-08 11:15:38Z stefan $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPUTILS_HPP__
  9. #define __IPUTILS_HPP__
  10. // Standard Ip Include Files
  11. #include "IpTypes.hpp"
  12. #include "IpDebug.hpp"
  13. namespace Ipopt
  14. {
  15. inline Index Max(Index a, Index b)
  16. {
  17. return ((a) > (b) ? (a) : (b));
  18. }
  19. inline Index Max(Index a, Index b, Index c)
  20. {
  21. Index max = Max(a,b);
  22. max = Max(max, c);
  23. return max;
  24. }
  25. inline Index Max(Index a, Index b, Index c, Index d)
  26. {
  27. Index max = Max(a, b, c);
  28. max = Max(max, d);
  29. return max;
  30. }
  31. inline Index Min(Index a, Index b)
  32. {
  33. return ((a) < (b) ? (a) : (b));
  34. }
  35. inline Index Min(Index a, Index b, Index c)
  36. {
  37. Index min = Min(a,b);
  38. min = Min(min, c);
  39. return min;
  40. }
  41. inline Index Min(Index a, Index b, Index c, Index d)
  42. {
  43. Index min = Min(a, b, c);
  44. min = Min(min, d);
  45. return min;
  46. }
  47. ///////////////////////////////////////////
  48. inline Number Max(Number a, Number b)
  49. {
  50. return ((a) > (b) ? (a) : (b));
  51. }
  52. inline Number Max(Number a, Number b, Number c)
  53. {
  54. Number max = Max(a,b);
  55. max = Max(max, c);
  56. return max;
  57. }
  58. inline Number Max(Number a, Number b, Number c, Number d)
  59. {
  60. Number max = Max(a, b, c);
  61. max = Max(max, d);
  62. return max;
  63. }
  64. inline Number Min(Number a, Number b)
  65. {
  66. return ((a) < (b) ? (a) : (b));
  67. }
  68. inline Number Min(Number a, Number b, Number c)
  69. {
  70. Number min = Min(a,b);
  71. min = Min(min, c);
  72. return min;
  73. }
  74. inline Number Min(Number a, Number b, Number c, Number d)
  75. {
  76. Number min = Min(a, b, c);
  77. min = Min(min, d);
  78. return min;
  79. }
  80. /** Function returning true iff the argument is a valid double number
  81. * (not NaN or Inf). */
  82. bool IsFiniteNumber(Number val);
  83. /** Function returning a random number between 0 and 1 */
  84. Number IpRandom01();
  85. /** Function resetting the random number generator */
  86. void IpResetRandom01();
  87. /** method determining CPU time */
  88. Number CpuTime();
  89. /** method determining system time */
  90. Number SysTime();
  91. /** method determining wallclock time since first call */
  92. Number WallclockTime();
  93. /** Method for comparing two numbers within machine precision. The
  94. * return value is true if lhs is less or equal the rhs, relaxing
  95. * this inequality by something a little larger than machine
  96. * precision relative to the absolute value of BasVal. */
  97. bool Compare_le(Number lhs, Number rhs, Number BasVal);
  98. /** Method for printing a formatted output to a string with given size.
  99. */
  100. int Snprintf(char* str, long size, const char* format, ...);
  101. } //namespace Ipopt
  102. #endif