Math   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A gcd() 0 4 2
A isZero() 0 4 2
A isGreaterThan() 0 4 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace ExtendedStrings\Strings;
6
7
class Math
8
{
9
    const EPSILON = 0.0000000001;
10
11
    /**
12
     * Returns the greatest common divisor of two floats.
13
     *
14
     * @param float $a
15
     * @param float $b
16
     *
17
     * @return float
18
     */
19
    public static function gcd(float $a, float $b): float
20
    {
21
        return self::isZero($b) ? $a : self::gcd($b, fmod($a, $b));
22
    }
23
24
    /**
25
     * Tests whether a float is zero.
26
     *
27
     * @param float $x
28
     *
29
     * @return bool
30
     */
31
    public static function isZero(float $x): bool
32
    {
33
        return $x === 0 || abs($x) < self::EPSILON;
34
    }
35
36
    /**
37
     * Tests whether a number is greater than another.
38
     *
39
     * @param float $a
40
     * @param float $b
41
     *
42
     * @return bool
43
     */
44
    public static function isGreaterThan(float $a, float $b): bool
45
    {
46
        return $a > $b && $a - $b > self::EPSILON;
47
    }
48
}
49