num/linear_fn.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | namespace wala { | ||
| 4 | |||
| 5 | // Linear function x -> a * x + b over num. | ||
| 6 | // operator* is composition: (f * g)(x) = f(g(x)). | ||
| 7 | // Default-constructs to the identity. | ||
| 8 |
2/2✓ Branch 26 → 27 taken 1359591 times.
✓ Branch 27 → 28 taken 1359136 times.
|
20572263 | template <typename num> struct linear_fn { |
| 9 | 3 | num a = 1; | |
| 10 | 3 | num b = 0; | |
| 11 |
2/2✓ Branch 2 → 3 taken 15776233 times.
✓ Branch 2 → 4 taken 15782534 times.
|
31558775 | num operator()(const num& x) const { return a * x + b; } |
| 12 | 400691283 | friend linear_fn operator*(const linear_fn& f, const linear_fn& g) { | |
| 13 |
2/2✓ Branch 2 → 3 taken 301554397 times.
✓ Branch 2 → 4 taken 99136880 times.
|
400691283 | return {f.a * g.a, f.a * g.b + f.b}; |
| 14 | } | ||
| 15 | 1 | linear_fn& operator*=(const linear_fn& o) { return *this = *this * o; } | |
| 16 |
1/2✓ Branch 7 → 8 taken 3 times.
✗ Branch 7 → 15 not taken.
|
9 | friend bool operator==(const linear_fn&, const linear_fn&) = default; |
| 17 | }; | ||
| 18 | |||
| 19 | } // namespace wala | ||
| 20 |