rounding_func.qbk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. [section:rounding Rounding Truncation and Integer Conversion]
  2. [section:round Rounding Functions]
  3. ``#include <boost/math/special_functions/round.hpp>``
  4. template <class T>
  5. T round(const T& v);
  6. template <class T, class Policy>
  7. T round(const T& v, const Policy&);
  8. template <class T>
  9. int iround(const T& v);
  10. template <class T, class Policy>
  11. int iround(const T& v, const Policy&);
  12. template <class T>
  13. long lround(const T& v);
  14. template <class T, class Policy>
  15. long lround(const T& v, const Policy&);
  16. template <class T>
  17. long long llround(const T& v);
  18. template <class T, class Policy>
  19. long long llround(const T& v, const Policy&);
  20. These functions return the closest integer to the argument /v/.
  21. Halfway cases are rounded away from zero, regardless of the current rounding
  22. direction.
  23. If the argument /v/ is either non-finite or else outside the range
  24. of the result type, then returns the result of __rounding_error: by
  25. default this throws an instance of `boost::math::rounding_error`.
  26. [endsect]
  27. [section:trunc Truncation Functions]
  28. ``#include <boost/math/special_functions/trunc.hpp>``
  29. template <class T>
  30. T trunc(const T& v);
  31. template <class T, class Policy>
  32. T trunc(const T& v, const Policy&);
  33. template <class T>
  34. int itrunc(const T& v);
  35. template <class T, class Policy>
  36. int itrunc(const T& v, const Policy&);
  37. template <class T>
  38. long ltrunc(const T& v);
  39. template <class T, class Policy>
  40. long ltrunc(const T& v, const Policy&);
  41. template <class T>
  42. long long lltrunc(const T& v);
  43. template <class T, class Policy>
  44. long long lltrunc(const T& v, const Policy&);
  45. The trunc functions round their argument to the integer value,
  46. nearest to but no larger in magnitude than the argument.
  47. For example `itrunc(3.7)` would return `3` and `ltrunc(-4.6)`
  48. would return `-4`.
  49. If the argument /v/ is either non-finite or else outside the range
  50. of the result type, then returns the result of __rounding_error: by
  51. default this throws an instance of `boost::math::rounding_error`.
  52. [endsect]
  53. [section:modf Integer and Fractional Part Splitting (modf)]
  54. ``#include <boost/math/special_functions/modf.hpp>``
  55. template <class T>
  56. T modf(const T& v, T* ipart);
  57. template <class T, class Policy>
  58. T modf(const T& v, T* ipart, const Policy&);
  59. template <class T>
  60. T modf(const T& v, int* ipart);
  61. template <class T, class Policy>
  62. T modf(const T& v, int* ipart, const Policy&);
  63. template <class T>
  64. T modf(const T& v, long* ipart);
  65. template <class T, class Policy>
  66. T modf(const T& v, long* ipart, const Policy&);
  67. template <class T>
  68. T modf(const T& v, long long* ipart);
  69. template <class T, class Policy>
  70. T modf(const T& v, long long* ipart, const Policy&);
  71. The `modf` functions store the integer part of /v/ in `*ipart`
  72. and return the fractional part of /v/. The sign of the integer
  73. and fractional parts are the same as the sign of /v/.
  74. If the argument /v/ is either non-finite or else outside the range
  75. of the result type, then returns the result of __rounding_error: by
  76. default this throws an instance of `boost::math::rounding_error`.
  77. [endsect]
  78. [endsect] [/section:rounding Rounding Truncation and Integer Conversion]
  79. [/
  80. Copyright 2006 John Maddock and Paul A. Bristow.
  81. Distributed under the Boost Software License, Version 1.0.
  82. (See accompanying file LICENSE_1_0.txt or copy at
  83. http://www.boost.org/LICENSE_1_0.txt).
  84. ]