math: fix factorial_test.v error
parent
bf20b01586
commit
89b83400f5
|
@ -13,13 +13,13 @@ import math
|
||||||
pub fn factorial(n f64) f64 {
|
pub fn factorial(n f64) f64 {
|
||||||
// For a large postive argument (n >= FACTORIALS.len) return max_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
|
return math.max_f64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise return n!.
|
// Otherwise return n!.
|
||||||
if n == f64(i64(n)) && n >= 0.0 {
|
if n == f64(i64(n)) && n >= 0.0 {
|
||||||
return FACTORIALS[i64(n)]
|
return factorials_table[i64(n)]
|
||||||
}
|
}
|
||||||
|
|
||||||
return math.gamma(n + 1.0)
|
return math.gamma(n + 1.0)
|
||||||
|
@ -37,8 +37,8 @@ pub fn log_factorial(n f64) f64 {
|
||||||
|
|
||||||
if n != f64(i64(n)) {
|
if n != f64(i64(n)) {
|
||||||
return math.log_gamma(n+1)
|
return math.log_gamma(n+1)
|
||||||
} else if n < LOG_FACTORIALS.len {
|
} else if n < log_factorials_table.len {
|
||||||
return LOG_FACTORIALS[i64(n)]
|
return log_factorials_table[i64(n)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise return asymptotic expansion of ln(n!).
|
// Otherwise return asymptotic expansion of ln(n!).
|
||||||
|
|
|
@ -23,7 +23,7 @@ const (
|
||||||
-174611.0 / (330.0 * 20.0 * 19.0)
|
-174611.0 / (330.0 * 20.0 * 19.0)
|
||||||
]
|
]
|
||||||
|
|
||||||
FACTORIALS = [
|
factorials_table = [
|
||||||
f64(1.000000000000000000000e+0), /* 0! */
|
f64(1.000000000000000000000e+0), /* 0! */
|
||||||
1.000000000000000000000e+0, /* 1! */
|
1.000000000000000000000e+0, /* 1! */
|
||||||
2.000000000000000000000e+0, /* 2! */
|
2.000000000000000000000e+0, /* 2! */
|
||||||
|
@ -197,7 +197,7 @@ const (
|
||||||
7.257415615307998967397e+306 /* 170! */
|
7.257415615307998967397e+306 /* 170! */
|
||||||
]
|
]
|
||||||
|
|
||||||
LOG_FACTORIALS = [
|
log_factorials_table = [
|
||||||
f64(0.000000000000000000000e+0), /* 0! */
|
f64(0.000000000000000000000e+0), /* 0! */
|
||||||
0.000000000000000000000e+0, /* 1! */
|
0.000000000000000000000e+0, /* 1! */
|
||||||
6.931471805599453094172e-1, /* 2! */
|
6.931471805599453094172e-1, /* 2! */
|
||||||
|
|
Loading…
Reference in New Issue