mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
math: fix factorial_test.v error
This commit is contained in:
parent
bf20b01586
commit
89b83400f5
@ -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++ {
|
||||
|
@ -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! */
|
||||
|
Loading…
Reference in New Issue
Block a user