Skip to content

Instantly share code, notes, and snippets.

@MLLeKander
Last active August 29, 2015 14:00
Show Gist options
  • Save MLLeKander/6cadb14791b26c71e7cc to your computer and use it in GitHub Desktop.
Save MLLeKander/6cadb14791b26c71e7cc to your computer and use it in GitHub Desktop.
func smallOkay(x, z float64) (float64, float64, bool) {
for x < 0 {
if x > -1e-09 {
return x, z, true
}
z = z / x
x = x + 1
}
for x < 2 {
if x < 1e-09 {
return x, z, true
}
z = z / x
x = x + 1
}
return x, z, false
}
func stuff(x float64) float64 {
z := 1.0
for x >= 3 {
x = x - 1
z = z * x
}
x, z, smallFastPath := smallOkay(x, z)
if smallFastPath {
if x == 0 {
return Inf(1)
}
return z / ((1 + Euler*x) * x)
}
if x == 2 {
return z
}
x = x - 2
p = (((((x*_gamP[0]+_gamP[1])*x+_gamP[2])*x+_gamP[3])*x+_gamP[4])*x+_gamP[5])*x + _gamP[6]
q = ((((((x*_gamQ[0]+_gamQ[1])*x+_gamQ[2])*x+_gamQ[3])*x+_gamQ[4])*x+_gamQ[5])*x+_gamQ[6])*x + _gamQ[7]
return z * p / q
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment