// 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
}
// 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
}