overflow.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Boost test/overflow.cpp
  2. * test if extended precision exponent does not disturb interval computation
  3. *
  4. * Copyright 2002-2003 Guillaume Melquiond
  5. *
  6. * Distributed under the Boost Software License, Version 1.0.
  7. * (See accompanying file LICENSE_1_0.txt or
  8. * copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #include <boost/numeric/interval.hpp>
  11. #include <boost/test/minimal.hpp>
  12. #include "bugs.hpp"
  13. template<class I>
  14. void test_one(typename I::base_type x, typename I::base_type f) {
  15. I y = x;
  16. typename I::base_type g = 1 / f;
  17. const int nb = 10000;
  18. for(int i = 0; i < nb; i++) y *= f;
  19. for(int i = 0; i < nb; i++) y *= g;
  20. BOOST_CHECK(in(x, y));
  21. # ifdef __BORLANDC__
  22. ::detail::ignore_unused_variable_warning(nb);
  23. # endif
  24. }
  25. template<class I>
  26. void test() {
  27. test_one<I>(1., 25.);
  28. test_one<I>(1., 0.04);
  29. test_one<I>(-1., 25.);
  30. test_one<I>(-1., 0.04);
  31. }
  32. int test_main(int, char *[]) {
  33. test<boost::numeric::interval<float> >();
  34. test<boost::numeric::interval<double> >();
  35. //test<boost::numeric::interval<long double> >();
  36. # ifdef __BORLANDC__
  37. ::detail::ignore_warnings();
  38. # endif
  39. return 0;
  40. }