1 /* specfunc/elementary.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
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.
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.
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.
20 /* Author: G. Jungman */
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_errno.h>
25 #include <gsl/gsl_sf_elementary.h>
31 gsl_sf_multiply_e(const double x, const double y, gsl_sf_result * result)
33 const double ax = fabs(x);
34 const double ay = fabs(y);
36 if(x == 0.0 || y == 0.0) {
37 /* It is necessary to eliminate this immediately.
43 else if((ax <= 1.0 && ay >= 1.0) || (ay <= 1.0 && ax >= 1.0)) {
44 /* Straddling 1.0 is always safe.
47 result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
51 const double f = 1.0 - 2.0 * GSL_DBL_EPSILON;
52 const double min = GSL_MIN_DBL(fabs(x), fabs(y));
53 const double max = GSL_MAX_DBL(fabs(x), fabs(y));
54 if(max < 0.9 * GSL_SQRT_DBL_MAX || min < (f * DBL_MAX)/max) {
55 result->val = GSL_COERCE_DBL(x*y);
56 result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
57 CHECK_UNDERFLOW(result);
61 OVERFLOW_ERROR(result);
68 gsl_sf_multiply_err_e(const double x, const double dx,
69 const double y, const double dy,
70 gsl_sf_result * result)
72 int status = gsl_sf_multiply_e(x, y, result);
73 result->err += fabs(dx*y) + fabs(dy*x);
78 /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
82 double gsl_sf_multiply(const double x, const double y)
84 EVAL_RESULT(gsl_sf_multiply_e(x, y, &result));