abs_valarray.pass.cpp 924 B

12345678910111213141516171819202122232425262728293031323334
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <valarray>
  10. // template<class T> class valarray;
  11. // template<class T>
  12. // valarray<T>
  13. // abs(const valarray<T>& x);
  14. #include <valarray>
  15. #include <cassert>
  16. int main()
  17. {
  18. {
  19. typedef double T;
  20. T a1[] = {1.5, -2.5, 3.4, -4.5, -5.0};
  21. T a3[] = {1.5, 2.5, 3.4, 4.5, 5.0};
  22. const unsigned N = sizeof(a1)/sizeof(a1[0]);
  23. std::valarray<T> v1(a1, N);
  24. std::valarray<T> v3 = abs(v1);
  25. assert(v3.size() == v1.size());
  26. for (int i = 0; i < v3.size(); ++i)
  27. assert(v3[i] == a3[i]);
  28. }
  29. }