1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* specfunc/result.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Author: G. Jungman */
#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_exp.h>
#include <gsl/gsl_sf_result.h>
int
gsl_sf_result_smash_e(const gsl_sf_result_e10 * re, gsl_sf_result * r)
{
if(re->e10 == 0) {
/* nothing to smash */
r->val = re->val;
r->err = re->err;
return GSL_SUCCESS;
}
else {
const double av = fabs(re->val);
const double ae = fabs(re->err);
if( GSL_SQRT_DBL_MIN < av && av < GSL_SQRT_DBL_MAX
&& GSL_SQRT_DBL_MIN < ae && ae < GSL_SQRT_DBL_MAX
&& 0.49*GSL_LOG_DBL_MIN < re->e10 && re->e10 < 0.49*GSL_LOG_DBL_MAX
) {
const double scale = exp(re->e10 * M_LN10);
r->val = re->val * scale;
r->err = re->err * scale;
return GSL_SUCCESS;
}
else {
return gsl_sf_exp_mult_err_e(re->e10*M_LN10, 0.0, re->val, re->err, r);
}
}
/*
int stat_v;
int stat_e;
if(re->val == 0.0) {
r->val = 0.0;
stat_v = GSL_SUCCESS;
}
else {
gsl_sf_result r_val;
const double s = GSL_SIGN(re->val);
const double x_v = re->e10*M_LN10 + log(fabs(re->val));
stat_v = gsl_sf_exp_e(x_v, &r_val);
r->val = s * r_val.val;
}
if(re->err == 0.0) {
r->err = 0.0;
stat_e = GSL_SUCCESS;
}
else if(re->val != 0.0) {
r->err = fabs(r->val * re->err/re->val);
stat_e = GSL_SUCCESS;
}
else {
gsl_sf_result r_err;
const double x_e = re->e10*M_LN10 + log(fabs(re->err));
stat_e = gsl_sf_exp_e(x_e, &r_err);
r->err = r_err.val;
}
return GSL_ERROR_SELECT_2(stat_v, stat_e);
*/
}
|