acos_valarray.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // acos(const valarray<T>& x);
  14. #include <valarray>
  15. #include <cassert>
  16. #include <sstream>
  17. bool is_about(double x, double y, int p)
  18. {
  19. std::ostringstream o;
  20. o.precision(p);
  21. scientific(o);
  22. o << x;
  23. std::string a = o.str();
  24. o.str("");
  25. o << y;
  26. return a == o.str();
  27. }
  28. int main()
  29. {
  30. {
  31. typedef double T;
  32. T a1[] = {-.9, -.5, 0., .5, .75};
  33. T a3[] = {2.6905658417935308e+00,
  34. 2.0943951023931957e+00,
  35. 1.5707963267948966e+00,
  36. 1.0471975511965976e+00,
  37. 7.2273424781341566e-01};
  38. const unsigned N = sizeof(a1)/sizeof(a1[0]);
  39. std::valarray<T> v1(a1, N);
  40. std::valarray<T> v3 = acos(v1);
  41. assert(v3.size() == v1.size());
  42. for (int i = 0; i < v3.size(); ++i)
  43. assert(is_about(v3[i], a3[i], 10));
  44. }
  45. }