Пример #1
0
// Modf returns integer and fractional floating-point numbers
// that sum to f.  Both values have the same sign as f.
//
// Special cases are:
//	Modf(±Inf) = ±Inf, NaN
//	Modf(NaN) = NaN, NaN
func Modf(f float64) (int float64, frac float64) {
	// approach inspired by GopherJS, see that project for copyright etc
	//if f == posInf || f == negInf {
	if !hx.CallBool("", "Math.isFinite", 1, f) {
		return f, hx.GetFloat("", "Math.NaN")
	}
	frac = Mod(f, 1)
	return f - frac, frac
}
Пример #2
0
// Pow returns x**y, the base-x exponential of y.
//
// Special cases are (in order):
//	Pow(x, ±0) = 1 for any x
//	Pow(1, y) = 1 for any y
//	Pow(x, 1) = x for any x
//	Pow(NaN, y) = NaN
//	Pow(x, NaN) = NaN
//	Pow(±0, y) = ±Inf for y an odd integer < 0
//	Pow(±0, -Inf) = +Inf
//	Pow(±0, +Inf) = +0
//	Pow(±0, y) = +Inf for finite y < 0 and not an odd integer
//	Pow(±0, y) = ±0 for y an odd integer > 0
//	Pow(±0, y) = +0 for finite y > 0 and not an odd integer
//	Pow(-1, ±Inf) = 1
//	Pow(x, +Inf) = +Inf for |x| > 1
//	Pow(x, -Inf) = +0 for |x| > 1
//	Pow(x, +Inf) = +0 for |x| < 1
//	Pow(x, -Inf) = +Inf for |x| < 1
//	Pow(+Inf, y) = +Inf for y > 0
//	Pow(+Inf, y) = +0 for y < 0
//	Pow(-Inf, y) = Pow(-0, -y)
//	Pow(x, y) = NaN for finite x < 0 and finite non-integer y
func Pow(x, y float64) float64 {
	if runtime.GOARCH == "cs" {
		return pow(x, y)
	}
	// follow GopherJS approach for copyright etc see that project
	/*
		if x == 1 || (x == -1 && (y == posInf || y == negInf)) {
			return 1
		}
		return math.Call("pow", x, y).Float()
	*/
	if x == 1 || (x == -1 && !hx.CallBool("", "Math.isFinite", 1, y) && (y < SmallestNonzeroFloat64 || y > MaxFloat64)) {
		return 1
	}
	if x == -1 && IsNaN(y) {
		return NaN()
	}
	return hx.CallFloat("", "Math.pow", 2, x, y)
}