• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / math / 21599391071

02 Feb 2026 04:57PM UTC coverage: 99.306%. Remained the same
21599391071

push

github

BenMorel
Prepare for release

1288 of 1297 relevant lines covered (99.31%)

1103.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/Internal/Calculator/BcMathCalculator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Math\Internal\Calculator;
6

7
use Brick\Math\Internal\Calculator;
8
use Override;
9

10
use function bcadd;
11
use function bcdiv;
12
use function bcmod;
13
use function bcmul;
14
use function bcpow;
15
use function bcpowmod;
16
use function bcsqrt;
17
use function bcsub;
18

19
/**
20
 * Calculator implementation built around the bcmath library.
21
 *
22
 * @internal
23
 */
24
final readonly class BcMathCalculator extends Calculator
25
{
26
    #[Override]
27
    public function add(string $a, string $b): string
28
    {
29
        return bcadd($a, $b, 0);
1,715✔
30
    }
31

32
    #[Override]
33
    public function sub(string $a, string $b): string
34
    {
35
        return bcsub($a, $b, 0);
385✔
36
    }
37

38
    #[Override]
39
    public function mul(string $a, string $b): string
40
    {
41
        return bcmul($a, $b, 0);
1,950✔
42
    }
43

44
    #[Override]
45
    public function divQ(string $a, string $b): string
46
    {
47
        return bcdiv($a, $b, 0);
711✔
48
    }
49

50
    #[Override]
51
    public function divR(string $a, string $b): string
52
    {
53
        return bcmod($a, $b, 0);
1,468✔
54
    }
55

56
    #[Override]
57
    public function divQR(string $a, string $b): array
58
    {
59
        $q = bcdiv($a, $b, 0);
2,084✔
60
        $r = bcmod($a, $b, 0);
2,084✔
61

62
        return [$q, $r];
2,084✔
63
    }
64

65
    #[Override]
66
    public function pow(string $a, int $e): string
67
    {
68
        return bcpow($a, (string) $e, 0);
560✔
69
    }
70

71
    #[Override]
72
    public function modPow(string $base, string $exp, string $mod): string
73
    {
74
        // normalize to Euclidean representative so modPow() stays consistent with mod()
75
        $base = $this->mod($base, $mod);
59✔
76

77
        return bcpowmod($base, $exp, $mod, 0);
59✔
78
    }
79

80
    #[Override]
81
    public function sqrt(string $n): string
82
    {
83
        return bcsqrt($n, 0);
486✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc