GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch dev (ec2832)
by t
03:09
created

FMAT::fact()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 13
ccs 10
cts 10
cp 1
crap 4
rs 9.9666
1
<?php
2
/**
3
 * Trait MathAndTrigonometry-F
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
namespace icy2003\php\icomponents\excel\mathAndTrigonometry;
10
11
use icy2003\php\ihelpers\Arrays;
12
13
/**
14
 * MathAndTrigonometry-F
15
 */
16
trait FMAT
17
{
18
    /**
19
     * 返回数的阶乘
20
     *
21
     * @param integer|double $number 必需。 要计算其阶乘的非负数。 如果 number 不是整数,将被截尾取整
22
     *
23
     * @return integer|false
24
     */
25 4
    public static function fact($number)
26
    {
27 4
        $number = (int) floor($number);
28 4
        if ($number == 0) {
29 1
            return 1;
30 4
        } elseif ($number < 0) {
31 1
            return false;
32
        }
33 4
        $result = 1;
34 4
        foreach (Arrays::rangeGenerator(1, $number) as $num) {
35 4
            $result *= $num;
36
        }
37 4
        return $result;
38
    }
39
40
    /**
41
     * 返回数字的双倍阶乘
42
     *
43
     * - 偶数:n!! = n * (n - 2) * (n - 4) * ... * 4 * 2
44
     * - 奇数:n!! = n * (n - 2) * (n - 4) * ... * 3 * 1
45
     *
46
     * @param integer $number 必需。 为其返回双倍阶乘的值。 如果 number 不是整数,将被截尾取整
47
     *
48
     * @return integer
49
     */
50 1
    public static function factdouble($number)
51
    {
52 1
        if ($number == 0) {
53 1
            return 1;
54
        }
55 1
        $result = 1;
56 1
        $isEven = $number % 2 == 0;
57 1
        foreach (Arrays::rangeGenerator($isEven ? 2 : 1, (int) $number, 2) as $num) {
58 1
            $result *= $num;
59
        }
60 1
        return $result;
61
    }
62
63
    /**
64
     * 将参数 number 向下舍入(沿绝对值减小的方向)为最接近的 significance 的倍数
65
     *
66
     * @param double $number 必需。 要舍入的数值
67
     * @param double $significance 必需。 要舍入到的倍数
68
     *
69
     * @return double|false
70
     */
71 1
    public static function floor($number, $significance = 1)
72
    {
73 1
        return (is_numeric($number) && is_numeric($significance)) && ($number * $significance > 0) ? (floor($number / $significance) * $significance) : false;
0 ignored issues
show
introduced by
The condition is_numeric($significance) is always true.
Loading history...
74
    }
75
}
76