lib/math/rational.c
Source file repositories/reference/linux-study-clean/lib/math/rational.c
File Facts
- System
- Linux kernel
- Corpus path
lib/math/rational.c- Extension
.c- Size
- 3111 bytes
- Lines
- 113
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
Dependency Surface
linux/rational.hlinux/compiler.hlinux/export.hlinux/minmax.hlinux/limits.hlinux/module.h
Detected Declarations
function rational_best_approximationexport rational_best_approximation
Annotated Snippet
if ((n2 > max_numerator) || (d2 > max_denominator)) {
unsigned long t = ULONG_MAX;
if (d1)
t = (max_denominator - d0) / d1;
if (n1)
t = min(t, (max_numerator - n0) / n1);
/* This tests if the semi-convergent is closer than the previous
* convergent. If d1 is zero there is no previous convergent as this
* is the 1st iteration, so always choose the semi-convergent.
*/
if (!d1 || 2u * t > a || (2u * t == a && d0 * dp > d1 * d)) {
n1 = n0 + t * n1;
d1 = d0 + t * d1;
}
break;
}
n0 = n1;
n1 = n2;
d0 = d1;
d1 = d2;
}
*best_numerator = n1;
*best_denominator = d1;
}
EXPORT_SYMBOL(rational_best_approximation);
MODULE_DESCRIPTION("Rational fraction support library");
MODULE_LICENSE("GPL v2");
Annotation
- Immediate include surface: `linux/rational.h`, `linux/compiler.h`, `linux/export.h`, `linux/minmax.h`, `linux/limits.h`, `linux/module.h`.
- Detected declarations: `function rational_best_approximation`, `export rational_best_approximation`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.