1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: make v test-cleancode test everything by default (#10050)

This commit is contained in:
Delyan Angelov
2021-05-08 13:32:29 +03:00
committed by GitHub
parent cba2cb6b9c
commit 8a380f4699
132 changed files with 3230 additions and 3440 deletions

View File

@@ -14,7 +14,7 @@ pub fn factorial(n f64) f64 {
// For a large postive argument (n >= FACTORIALS.len) return max_f64
if n >= factorials_table.len {
return math.max_f64
return math.max_f64
}
// Otherwise return n!.
@@ -30,51 +30,51 @@ pub fn log_factorial(n f64) f64 {
// For a large postive argument (n < 0) return max_f64
if n < 0 {
return -math.max_f64
return -math.max_f64
}
// If n < N then return ln(n!).
if n != f64(i64(n)) {
return math.log_gamma(n+1)
return math.log_gamma(n + 1)
} else if n < log_factorials_table.len {
return log_factorials_table[i64(n)]
}
return log_factorials_table[i64(n)]
}
// Otherwise return asymptotic expansion of ln(n!).
return log_factorial_asymptotic_expansion(int(n))
return log_factorial_asymptotic_expansion(int(n))
}
fn log_factorial_asymptotic_expansion(n int) f64 {
m := 6
mut term := []f64{}
xx := f64((n + 1) * (n + 1))
mut xj := f64(n + 1)
m := 6
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)
log_factorial := log_sqrt_2pi - xj + (xj - 0.5) * math.log(xj)
mut i := 0
mut i := 0
for i = 0; i < m; i++ {
term << b_numbers[i] / xj
xj *= xx
}
for i = 0; i < m; i++ {
term << b_numbers[i] / xj
xj *= xx
}
mut sum := term[m-1]
mut sum := term[m - 1]
for i = m - 2; i >= 0; i-- {
if math.abs(sum) <= math.abs(term[i]) {
break
}
for i = m - 2; i >= 0; i-- {
if math.abs(sum) <= math.abs(term[i]) {
break
}
sum = term[i]
}
sum = term[i]
}
for i >= 0 {
sum += term[i]
i--
}
for i >= 0 {
sum += term[i]
i--
}
return log_factorial + sum
return log_factorial + sum
}