Beispiel #1
0
func Exp_mult_e(x float64, y float64, result *Result) error {
	ay := math.Abs(y)

	if y == 0.0 {
		result.val = 0.0
		result.err = 0.0
		return err.SUCCESS
	} else if (x < 0.5*gsl.LOG_DBL_MAX && x > 0.5*gsl.LOG_DBL_MIN) && (ay < 0.8*gsl.SQRT_DBL_MAX && ay > 1.2*gsl.SQRT_DBL_MIN) {
		ex := math.Exp(x)
		result.val = y * ex
		result.err = (2.0 + math.Abs(x)) * gsl.DBL_EPSILON * math.Abs(result.val)
		return err.SUCCESS
	}

	ly := math.Log(ay)
	lnr := x + ly

	if lnr > gsl.LOG_DBL_MAX-0.01 {
		return OverflowError(result)
	} else if lnr < gsl.LOG_DBL_MIN+0.01 {
		return UnderflowError(result)
	}

	sy := gsl.Sign(y)
	M := math.Floor(x)
	N := math.Floor(ly)
	a := x - M
	b := ly - N
	berr := 2.0 * gsl.DBL_EPSILON * (math.Abs(ly) + math.Abs(N))
	result.val = float64(sy) * math.Exp(M+N) * math.Exp(a+b)
	result.err = berr * math.Abs(result.val)
	result.err += 2.0 * gsl.DBL_EPSILON * (M + N + 1.0) * math.Abs(result.val)
	return err.SUCCESS
}
Beispiel #2
0
func Exp_mult_err_e10_e(x, dx, y, dy float64, result *Result_e10) error {
	ay := math.Abs(y)

	if y == 0.0 {
		result.val = 0.0
		result.err = math.Abs(dy * math.Exp(x))
		result.e10 = 0
		return err.SUCCESS
	} else if (x < 0.5*gsl.LOG_DBL_MAX && x > 0.5*gsl.LOG_DBL_MIN) && (ay < 0.8*gsl.SQRT_DBL_MAX && ay > 1.2*gsl.SQRT_DBL_MIN) {
		ex := math.Exp(x)
		result.val = y * ex
		result.err = ex * (math.Abs(dy) + math.Abs(y*dx))
		result.err += 2.0 * gsl.DBL_EPSILON * math.Abs(result.val)
		result.e10 = 0
		return err.SUCCESS
	}

	ly := math.Log(ay)
	l10_val := (x + ly) / gsl.M_LN10

	if l10_val > math.MaxInt32-1 {
		return OverflowError_e10(result)
	} else if l10_val < math.MinInt32+1 {
		return UnderflowError_e10(result)
	}

	sy := gsl.Sign(y)
	N := int(math.Floor(l10_val))
	arg_val := (l10_val - float64(N)) * gsl.M_LN10
	arg_err := dy/math.Abs(y) + dx + 2.0*gsl.DBL_EPSILON*math.Abs(arg_val)

	result.val = float64(sy) * math.Exp(arg_val)
	result.err = arg_err * math.Abs(result.val)
	result.err += 2.0 * gsl.DBL_EPSILON * math.Abs(result.val)
	result.e10 = N

	return err.SUCCESS
}
Beispiel #3
0
func Exp_mult_err_e(x, dx, y, dy float64, result *Result) error {
	ay := math.Abs(y)

	if y == 0.0 {
		result.val = 0.0
		result.err = math.Abs(dy * math.Exp(x))
		return err.SUCCESS
	} else if (x < 0.5*gsl.LOG_DBL_MAX && x > 0.5*gsl.LOG_DBL_MIN) && (ay < 0.8*gsl.SQRT_DBL_MAX && ay > 1.2*gsl.SQRT_DBL_MIN) {
		ex := math.Exp(x)
		result.val = y * ex
		result.err = ex * (math.Abs(dy) + math.Abs(y*dx))
		result.err += 2.0 * gsl.DBL_EPSILON * math.Abs(result.val)
		return err.SUCCESS
	}

	ly := math.Log(ay)
	lnr := x + ly

	if lnr > gsl.LOG_DBL_MAX-0.01 {
		return OverflowError(result)
	} else if lnr < gsl.LOG_DBL_MIN+0.01 {
		return UnderflowError(result)
	}

	sy := gsl.Sign(y)
	M := math.Floor(x)
	N := math.Floor(ly)
	a := x - M
	b := ly - N
	eMN := math.Exp(M + N)
	eab := math.Exp(a + b)
	result.val = float64(sy) * eMN * eab
	result.err = eMN * eab * 2.0 * gsl.DBL_EPSILON
	result.err += eMN * eab * math.Abs(dy/y)
	result.err += eMN * eab * math.Abs(dx)
	return err.SUCCESS
}
Beispiel #4
0
func Lngamma_sgn_0(eps float64, lng *Result, sgn *float64) error {
	/* calculate series for g(eps) = Gamma(eps) eps - 1/(1+eps) - eps/2 */
	c1 := -0.07721566490153286061
	c2 := -0.01094400467202744461
	c3 := 0.09252092391911371098
	c4 := -0.01827191316559981266
	c5 := 0.01800493109685479790
	c6 := -0.00685088537872380685
	c7 := 0.00399823955756846603
	c8 := -0.00189430621687107802
	c9 := 0.00097473237804513221
	c10 := -0.00048434392722255893
	g6 := c6 + eps*(c7+eps*(c8+eps*(c9+eps*c10)))
	g := eps * (c1 + eps*(c2+eps*(c3+eps*(c4+eps*(c5+eps*g6)))))

	/* calculate Gamma(eps) eps, a positive quantity */
	gee := g + 1.0/(1.0+eps) + 0.5*eps

	lng.val = math.Log(gee / math.Abs(eps))
	lng.err = 4.0 * gsl.DBL_EPSILON * math.Abs(lng.val)
	*sgn = gsl.Sign(eps)

	return err.SUCCESS
}