gsl_fft__compare_source.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* fft/compare_source.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl_fft__compare.h"
  20. int
  21. FUNCTION(compare_complex,results) (const char *name_a, const BASE a[],
  22. const char *name_b, const BASE b[],
  23. size_t stride, size_t n,
  24. const double allowed_ticks)
  25. {
  26. size_t i;
  27. double ticks, max_ticks = 0;
  28. double dr, di;
  29. const char *flag;
  30. for (i = 0; i < n; i++)
  31. {
  32. dr = b[2*stride*i] - a[2*stride*i];
  33. di = b[2*stride*i+1] - a[2*stride*i+1];
  34. ticks = (fabs (dr) + fabs (di)) / BASE_EPSILON;
  35. if (ticks > max_ticks)
  36. {
  37. max_ticks = ticks;
  38. }
  39. }
  40. if (max_ticks < allowed_ticks)
  41. {
  42. return 0;
  43. }
  44. printf ("\n%s vs %s : max_ticks = %f\n", name_a, name_b, max_ticks);
  45. for (i = 0; i < n; i++)
  46. {
  47. dr = b[2*stride*i] - a[2*stride*i];
  48. di = b[2*stride*i+1] - a[2*stride*i+1];
  49. ticks = (fabs (dr) + fabs (di)) / BASE_EPSILON;
  50. if (ticks > 1000)
  51. {
  52. flag = "***";
  53. }
  54. else
  55. {
  56. flag = "";
  57. }
  58. printf ("%15s: %d %.16f %.16f %s\n", name_a, (int)i,
  59. a[2*stride*i], a[2*stride*i+1], flag);
  60. printf ("%15s: %d %.16f %.16f %e %s\n", name_b, (int)i,
  61. b[2*stride*i], b[2*stride*i+1], ticks, flag);
  62. }
  63. return -1;
  64. }
  65. int
  66. FUNCTION(compare_real,results) (const char *name_a, const BASE a[],
  67. const char *name_b, const BASE b[],
  68. size_t stride, size_t n,
  69. const double allowed_ticks)
  70. {
  71. size_t i;
  72. double ticks, max_ticks = 0;
  73. double dr;
  74. const char *flag;
  75. for (i = 0; i < n; i++)
  76. {
  77. dr = b[stride*i] - a[stride*i];
  78. ticks = fabs (dr) / BASE_EPSILON;
  79. if (ticks > max_ticks)
  80. {
  81. max_ticks = ticks;
  82. }
  83. }
  84. if (max_ticks < allowed_ticks)
  85. {
  86. return 0;
  87. }
  88. printf ("\n%s vs %s : max_ticks = %f\n", name_a, name_b, max_ticks);
  89. for (i = 0; i < n; i++)
  90. {
  91. dr = b[stride*i] - a[stride*i];
  92. ticks = fabs (dr) / BASE_EPSILON;
  93. if (ticks > 1000)
  94. {
  95. flag = "***";
  96. }
  97. else
  98. {
  99. flag = "";
  100. }
  101. printf ("%15s: %d %.16f %s\n", name_a, (int)i,
  102. a[stride*i], flag);
  103. printf ("%15s: %d %.16f %e %s\n", name_b, (int)i,
  104. b[stride*i], ticks, flag);
  105. }
  106. return -1;
  107. }