1// 2007-02-04 Edward Smith-Rowland <3dw4rd@verizon.net> 2// 3// Copyright (C) 2007-2015 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 3, or (at your option) 9// any later version. 10// 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15// 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// comp_ellint_1 21 22 23// Compare against values generated by the GNU Scientific Library. 24// The GSL can be found on the web: http://www.gnu.org/software/gsl/ 25 26#include <tr1/cmath> 27#if defined(__TEST_DEBUG) 28#include <iostream> 29#define VERIFY(A) \ 30if (!(A)) \ 31 { \ 32 std::cout << "line " << __LINE__ \ 33 << " max_abs_frac = " << max_abs_frac \ 34 << std::endl; \ 35 } 36#else 37#include <testsuite_hooks.h> 38#endif 39#include "../testcase.h" 40 41 42// Test data. 43testcase_comp_ellint_1<double> data001[] = { 44 { 2.2805491384227703, -0.90000000000000002 }, 45 { 1.9953027776647296, -0.80000000000000004 }, 46 { 1.8456939983747236, -0.69999999999999996 }, 47 { 1.7507538029157526, -0.59999999999999998 }, 48 { 1.6857503548125963, -0.50000000000000000 }, 49 { 1.6399998658645112, -0.40000000000000002 }, 50 { 1.6080486199305126, -0.30000000000000004 }, 51 { 1.5868678474541664, -0.19999999999999996 }, 52 { 1.5747455615173562, -0.099999999999999978 }, 53 { 1.5707963267948966, 0.0000000000000000 }, 54 { 1.5747455615173562, 0.10000000000000009 }, 55 { 1.5868678474541664, 0.19999999999999996 }, 56 { 1.6080486199305126, 0.30000000000000004 }, 57 { 1.6399998658645112, 0.39999999999999991 }, 58 { 1.6857503548125963, 0.50000000000000000 }, 59 { 1.7507538029157526, 0.60000000000000009 }, 60 { 1.8456939983747236, 0.69999999999999996 }, 61 { 1.9953027776647296, 0.80000000000000004 }, 62 { 2.2805491384227699, 0.89999999999999991 }, 63}; 64 65// Test function. 66template <typename Tp> 67void test001() 68{ 69 const Tp eps = std::numeric_limits<Tp>::epsilon(); 70 Tp max_abs_diff = -Tp(1); 71 Tp max_abs_frac = -Tp(1); 72 unsigned int num_datum = sizeof(data001) 73 / sizeof(testcase_comp_ellint_1<double>); 74 for (unsigned int i = 0; i < num_datum; ++i) 75 { 76 const Tp f = std::tr1::comp_ellint_1(Tp(data001[i].k)); 77 const Tp f0 = data001[i].f0; 78 const Tp diff = f - f0; 79 if (std::abs(diff) > max_abs_diff) 80 max_abs_diff = std::abs(diff); 81 if (std::abs(f0) > Tp(10) * eps 82 && std::abs(f) > Tp(10) * eps) 83 { 84 const Tp frac = diff / f0; 85 if (std::abs(frac) > max_abs_frac) 86 max_abs_frac = std::abs(frac); 87 } 88 } 89 VERIFY(max_abs_frac < Tp(2.5000000000000020e-13)); 90} 91 92int main(int, char**) 93{ 94 test001<double>(); 95 return 0; 96} 97