test_sqrt_scaled_unit.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. \file
  12. \brief test_units_1.cpp
  13. \details
  14. Test unit class.
  15. Output:
  16. @verbatim
  17. @endverbatim
  18. **/
  19. #include "test_header.hpp"
  20. #include <boost/units/cmath.hpp>
  21. #include <boost/units/scale.hpp>
  22. #include <boost/units/make_scaled_unit.hpp>
  23. namespace bu = boost::units;
  24. static const double E_ = 2.718281828459045235360287471352662497757;
  25. typedef bu::make_scaled_unit<bu::length,
  26. bu::scale<10, bu::static_rational<-3> > >::type milli_meter_unit;
  27. typedef bu::make_scaled_unit<bu::area,
  28. bu::scale<10, bu::static_rational<-6> > >::type micro_meter2_unit;
  29. int test_main(int,char *[])
  30. {
  31. const bu::quantity<micro_meter2_unit> E1 = E_*micro_meter2_unit();
  32. const bu::quantity<milli_meter_unit> E2 = sqrt(E1);
  33. BOOST_CHECK(E1.value() == E_);
  34. BOOST_CHECK(E2.value() == sqrt(E_));
  35. return 0;
  36. }