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

PHPOffice / PhpSpreadsheet / 18013950625

25 Sep 2025 04:20PM UTC coverage: 95.867% (+0.3%) from 95.602%
18013950625

push

github

web-flow
Merge pull request #4663 from oleibman/tweakcoveralls

Tweak Coveralls

45116 of 47061 relevant lines covered (95.87%)

373.63 hits per line

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

92.31
/src/PhpSpreadsheet/Shared/Trend/ExponentialBestFit.php
1
<?php
2

3
namespace PhpOffice\PhpSpreadsheet\Shared\Trend;
4

5
class ExponentialBestFit extends BestFit
6
{
7
    /**
8
     * Algorithm type to use for best-fit
9
     * (Name of this Trend class).
10
     */
11
    protected string $bestFitType = 'exponential';
12

13
    /**
14
     * Return the Y-Value for a specified value of X.
15
     *
16
     * @param float $xValue X-Value
17
     *
18
     * @return float Y-Value
19
     */
20
    public function getValueOfYForX(float $xValue): float
10✔
21
    {
22
        return $this->getIntersect() * $this->getSlope() ** ($xValue - $this->xOffset);
10✔
23
    }
24

25
    /**
26
     * Return the X-Value for a specified value of Y.
27
     *
28
     * @param float $yValue Y-Value
29
     *
30
     * @return float X-Value
31
     */
32
    public function getValueOfXForY(float $yValue): float
×
33
    {
34
        return log(($yValue + $this->yOffset) / $this->getIntersect()) / log($this->getSlope());
×
35
    }
36

37
    /**
38
     * Return the Equation of the best-fit line.
39
     *
40
     * @param int $dp Number of places of decimal precision to display
41
     */
42
    public function getEquation(int $dp = 0): string
1✔
43
    {
44
        $slope = $this->getSlope($dp);
1✔
45
        $intersect = $this->getIntersect($dp);
1✔
46

47
        return 'Y = ' . $intersect . ' * ' . $slope . '^X';
1✔
48
    }
49

50
    /**
51
     * Return the Slope of the line.
52
     *
53
     * @param int $dp Number of places of decimal precision to display
54
     */
55
    public function getSlope(int $dp = 0): float
11✔
56
    {
57
        if ($dp != 0) {
11✔
58
            return round(exp($this->slope), $dp);
1✔
59
        }
60

61
        return exp($this->slope);
11✔
62
    }
63

64
    /**
65
     * Return the Value of X where it intersects Y = 0.
66
     *
67
     * @param int $dp Number of places of decimal precision to display
68
     */
69
    public function getIntersect(int $dp = 0): float
11✔
70
    {
71
        if ($dp != 0) {
11✔
72
            return round(exp($this->intersect), $dp);
1✔
73
        }
74

75
        return exp($this->intersect);
11✔
76
    }
77

78
    /**
79
     * Execute the regression and calculate the goodness of fit for a set of X and Y data values.
80
     *
81
     * @param float[] $yValues The set of Y-values for this regression
82
     * @param float[] $xValues The set of X-values for this regression
83
     */
84
    private function exponentialRegression(array $yValues, array $xValues, bool $const): void
9✔
85
    {
86
        $adjustedYValues = array_map(
9✔
87
            fn ($value): float => ($value < 0.0) ? 0 - log(abs($value)) : log($value),
9✔
88
            $yValues
9✔
89
        );
9✔
90

91
        $this->leastSquareFit($adjustedYValues, $xValues, $const);
9✔
92
    }
93

94
    /**
95
     * Define the regression and calculate the goodness of fit for a set of X and Y data values.
96
     *
97
     * @param float[] $yValues The set of Y-values for this regression
98
     * @param float[] $xValues The set of X-values for this regression
99
     */
100
    public function __construct(array $yValues, array $xValues = [], bool $const = true)
9✔
101
    {
102
        parent::__construct($yValues, $xValues);
9✔
103

104
        if (!$this->error) {
9✔
105
            $this->exponentialRegression($yValues, $xValues, (bool) $const);
9✔
106
        }
107
    }
108
}
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