You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7KB

  1. /*
  2. Command-line test of accuracy of Lambert W function implementations
  3. Copyright (C) 2015 Darko Veberic, darko.veberic@ijs.si
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <LambertW.h>
  16. #include <FukushimaLambertW.h>
  17. #include <iostream>
  18. #include <stdlib.h>
  19. #include <cmath>
  20. using namespace std;
  21. inline
  22. bool
  23. CloseTo(const double a, const double b, const double eps)
  24. {
  25. return fabs(a - b) < eps;
  26. }
  27. int
  28. main()
  29. {
  30. const double eps = 3e-15;
  31. const double step1 = 0.0001;
  32. const double max2 = 30;
  33. const double step2 = 0.0001;
  34. for (int branch = -1; branch <= 0; ++branch)
  35. for (double x = -1/M_E + eps; x < 0; x += step1) {
  36. const double w = utl::LambertW(branch, x);
  37. const double fw = Fukushima::LambertW(branch, x);
  38. if (!CloseTo(w, fw, eps)) {
  39. cout << 'f' << branch << '(' << x << ") = " << (w - fw) << endl;
  40. return EXIT_FAILURE;
  41. }
  42. }
  43. for (double x = 0; x < max2; x += step2) {
  44. const double w = utl::LambertW(0, x);
  45. const double fw = Fukushima::LambertW(0, x);
  46. if (!CloseTo(w, fw, eps)) {
  47. cout << "f0(" << x << ") = " << (w - fw) << endl;
  48. return EXIT_FAILURE;
  49. }
  50. }
  51. return EXIT_SUCCESS;
  52. }