// From F#:
func wWithinMargin(perfDiff, drawMargin float64) float64 {
	perfDiffAbs := math.Abs(perfDiff)
	denom := numerics.GaussCumulativeTo(drawMargin-perfDiffAbs) - numerics.GaussCumulativeTo(-drawMargin-perfDiffAbs)

	if denom < 2.222758749e-162 {
		return 1.0
	}
	vt := vWithinMargin(perfDiffAbs, drawMargin)

	return vt*vt + ((drawMargin-perfDiffAbs)*numerics.GaussAt(drawMargin-perfDiffAbs)-(-drawMargin-perfDiffAbs)*numerics.GaussAt(-drawMargin-perfDiffAbs))/denom
}
// from F#:
func vWithinMargin(perfDiff, drawMargin float64) float64 {
	perfDiffAbs := math.Abs(perfDiff)
	denom := numerics.GaussCumulativeTo(drawMargin-perfDiffAbs) - numerics.GaussCumulativeTo(-drawMargin-perfDiffAbs)
	if denom < 2.222758749e-162 {
		if perfDiff < 0.0 {
			return -perfDiff - drawMargin
		}
		return -perfDiff + drawMargin
	}

	numerator := numerics.GaussAt(-drawMargin-perfDiffAbs) - numerics.GaussAt(drawMargin-perfDiffAbs)
	if perfDiff < 0.0 {
		return -numerator / denom
	}
	return numerator / denom
}
func vExceedsMargin(perfDiff, drawMargin float64) float64 {
	denom := numerics.GaussCumulativeTo(perfDiff - drawMargin)
	if denom < 2.222758749e-162 {
		return -perfDiff + drawMargin
	}
	return numerics.GaussAt(perfDiff-drawMargin) / denom
}
func wExceedsMargin(perfDiff, drawMargin float64) float64 {
	denom := numerics.GaussCumulativeTo(perfDiff - drawMargin)
	if denom < 2.222758749e-162 {
		if perfDiff < 0.0 {
			return 1.0
		}
		return 0.0
	}

	vWin := vExceedsMargin(perfDiff, drawMargin)
	return vWin * (vWin + perfDiff - drawMargin)
}