unit.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 unit.cpp
  13. \details
  14. Test unit algebra.
  15. Output:
  16. @verbatim
  17. //[unit_output
  18. L = m
  19. L+L = m
  20. L-L = m
  21. L/L = dimensionless
  22. meter*meter = m^2
  23. M*(L/T)*(L/T) = m^2 kg s^-2
  24. M*(L/T)^2 = m^2 kg s^-2
  25. L^3 = m^3
  26. L^(3/2) = m^(3/2)
  27. 2vM = kg^(1/2)
  28. (3/2)vM = kg^(2/3)
  29. //]
  30. @endverbatim
  31. **/
  32. #include <iostream>
  33. #include "test_system.hpp"
  34. #include <boost/units/pow.hpp>
  35. int main()
  36. {
  37. using namespace boost::units;
  38. using namespace boost::units::test;
  39. //[unit_snippet_1
  40. const length L;
  41. const mass M;
  42. // needs to be namespace-qualified because of global time definition
  43. const boost::units::test::time T;
  44. const energy E;
  45. //]
  46. std::cout << "L = " << L << std::endl
  47. << "L+L = " << L+L << std::endl
  48. << "L-L = " << L-L << std::endl
  49. << "L/L = " << L/L << std::endl
  50. << "meter*meter = " << meter*meter << std::endl
  51. << "M*(L/T)*(L/T) = " << M*(L/T)*(L/T) << std::endl
  52. << "M*(L/T)^2 = " << M*pow<2>(L/T) << std::endl
  53. << "L^3 = " << pow<3>(L) << std::endl
  54. << "L^(3/2) = " << pow<static_rational<3,2> >(L)
  55. << std::endl
  56. << "2vM = " << root<2>(M) << std::endl
  57. << "(3/2)vM = " << root<static_rational<3,2> >(M)
  58. << std::endl;
  59. return 0;
  60. }