math: fix factorial_test.v error

pull/4310/head
yuyi 2020-04-09 10:21:11 +08:00 committed by GitHub
parent bf20b01586
commit 89b83400f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -13,13 +13,13 @@ import math
pub fn factorial(n f64) f64 {
// For a large postive argument (n >= FACTORIALS.len) return max_f64
if n >= FACTORIALS.len {
if n >= factorials_table.len {
return math.max_f64
}
// Otherwise return n!.
if n == f64(i64(n)) && n >= 0.0 {
return FACTORIALS[i64(n)]
return factorials_table[i64(n)]
}
return math.gamma(n + 1.0)
@ -37,8 +37,8 @@ pub fn log_factorial(n f64) f64 {
if n != f64(i64(n)) {
return math.log_gamma(n+1)
} else if n < LOG_FACTORIALS.len {
return LOG_FACTORIALS[i64(n)]
} else if n < log_factorials_table.len {
return log_factorials_table[i64(n)]
}
// Otherwise return asymptotic expansion of ln(n!).
@ -51,9 +51,9 @@ fn log_factorial_asymptotic_expansion(n int) f64 {
mut term := []f64
xx := f64((n + 1) * (n + 1))
mut xj := f64(n + 1)
log_factorial := log_sqrt_2pi - xj + (xj - 0.5) * math.log(xj)
mut i := 0
for i = 0; i < m; i++ {

View File

@ -23,7 +23,7 @@ const (
-174611.0 / (330.0 * 20.0 * 19.0)
]
FACTORIALS = [
factorials_table = [
f64(1.000000000000000000000e+0), /* 0! */
1.000000000000000000000e+0, /* 1! */
2.000000000000000000000e+0, /* 2! */
@ -197,7 +197,7 @@ const (
7.257415615307998967397e+306 /* 170! */
]
LOG_FACTORIALS = [
log_factorials_table = [
f64(0.000000000000000000000e+0), /* 0! */
0.000000000000000000000e+0, /* 1! */
6.931471805599453094172e-1, /* 2! */