gsl_specfunc__result.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* specfunc/result.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  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. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_sf_exp.h"
  24. #include "gsl_sf_result.h"
  25. int
  26. gsl_sf_result_smash_e(const gsl_sf_result_e10 * re, gsl_sf_result * r)
  27. {
  28. if(re->e10 == 0) {
  29. /* nothing to smash */
  30. r->val = re->val;
  31. r->err = re->err;
  32. return GSL_SUCCESS;
  33. }
  34. else {
  35. const double av = fabs(re->val);
  36. const double ae = fabs(re->err);
  37. if( GSL_SQRT_DBL_MIN < av && av < GSL_SQRT_DBL_MAX
  38. && GSL_SQRT_DBL_MIN < ae && ae < GSL_SQRT_DBL_MAX
  39. && 0.49*GSL_LOG_DBL_MIN < re->e10 && re->e10 < 0.49*GSL_LOG_DBL_MAX
  40. ) {
  41. const double scale = exp(re->e10 * M_LN10);
  42. r->val = re->val * scale;
  43. r->err = re->err * scale;
  44. return GSL_SUCCESS;
  45. }
  46. else {
  47. return gsl_sf_exp_mult_err_e(re->e10*M_LN10, 0.0, re->val, re->err, r);
  48. }
  49. }
  50. /*
  51. int stat_v;
  52. int stat_e;
  53. if(re->val == 0.0) {
  54. r->val = 0.0;
  55. stat_v = GSL_SUCCESS;
  56. }
  57. else {
  58. gsl_sf_result r_val;
  59. const double s = GSL_SIGN(re->val);
  60. const double x_v = re->e10*M_LN10 + log(fabs(re->val));
  61. stat_v = gsl_sf_exp_e(x_v, &r_val);
  62. r->val = s * r_val.val;
  63. }
  64. if(re->err == 0.0) {
  65. r->err = 0.0;
  66. stat_e = GSL_SUCCESS;
  67. }
  68. else if(re->val != 0.0) {
  69. r->err = fabs(r->val * re->err/re->val);
  70. stat_e = GSL_SUCCESS;
  71. }
  72. else {
  73. gsl_sf_result r_err;
  74. const double x_e = re->e10*M_LN10 + log(fabs(re->err));
  75. stat_e = gsl_sf_exp_e(x_e, &r_err);
  76. r->err = r_err.val;
  77. }
  78. return GSL_ERROR_SELECT_2(stat_v, stat_e);
  79. */
  80. }