lib/math/polynomial.c
Source file repositories/reference/linux-study-clean/lib/math/polynomial.c
File Facts
- System
- Linux kernel
- Corpus path
lib/math/polynomial.c- Extension
.c- Size
- 3595 bytes
- Lines
- 106
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/math.hlinux/module.hlinux/polynomial.h
Detected Declarations
function polynomial_calcexport polynomial_calc
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Generic polynomial calculation using integer coefficients.
*
* Copyright (C) 2020 BAIKAL ELECTRONICS, JSC
*
* Authors:
* Maxim Kaurkin <maxim.kaurkin@baikalelectronics.ru>
* Serge Semin <Sergey.Semin@baikalelectronics.ru>
*
*/
#include <linux/export.h>
#include <linux/math.h>
#include <linux/module.h>
#include <linux/polynomial.h>
/*
* The following conversion is an example:
*
* The original translation formulae of the temperature (in degrees of Celsius)
* to PVT data and vice-versa are following:
*
* N = 1.8322e-8*(T^4) + 2.343e-5*(T^3) + 8.7018e-3*(T^2) + 3.9269*(T^1) + 1.7204e2
* T = -1.6743e-11*(N^4) + 8.1542e-8*(N^3) + -1.8201e-4*(N^2) + 3.1020e-1*(N^1) - 4.838e1
*
* where T = [-48.380, 147.438]C and N = [0, 1023].
*
* They must be accordingly altered to be suitable for the integer arithmetics.
* The technique is called 'factor redistribution', which just makes sure the
* multiplications and divisions are made so to have a result of the operations
* within the integer numbers limit. In addition we need to translate the
* formulae to accept millidegrees of Celsius. Here what they look like after
* the alterations:
*
* N = (18322e-20*(T^4) + 2343e-13*(T^3) + 87018e-9*(T^2) + 39269e-3*T + 17204e2) / 1e4
* T = -16743e-12*(D^4) + 81542e-9*(D^3) - 182010e-6*(D^2) + 310200e-3*D - 48380
*
* where T = [-48380, 147438] mC and N = [0, 1023].
*
* static const struct polynomial poly_temp_to_N = {
* .total_divider = 10000,
* .terms = {
* {4, 18322, 10000, 10000},
* {3, 2343, 10000, 10},
* {2, 87018, 10000, 10},
* {1, 39269, 1000, 1},
* {0, 1720400, 1, 1}
* }
* };
*
* static const struct polynomial poly_N_to_temp = {
* .total_divider = 1,
* .terms = {
* {4, -16743, 1000, 1},
* {3, 81542, 1000, 1},
* {2, -182010, 1000, 1},
* {1, 310200, 1000, 1},
* {0, -48380, 1, 1}
* }
* };
*/
/**
* polynomial_calc - calculate a polynomial using integer arithmetic
*
* @poly: pointer to the descriptor of the polynomial
* @data: input value of the polynomial
*
* Calculate the result of a polynomial using only integer arithmetic. For
* this to work without too much loss of precision the coefficients has to
* be altered. This is called factor redistribution.
*
* Return: the result of the polynomial calculation.
*/
long polynomial_calc(const struct polynomial *poly, long data)
{
const struct polynomial_term *term = poly->terms;
long total_divider = poly->total_divider ?: 1;
long tmp, ret = 0;
int deg;
/*
* Here is the polynomial calculation function, which performs the
* redistributed terms calculations. It's pretty straightforward.
* We walk over each degree term up to the free one, and perform
* the redistributed multiplication of the term coefficient, its
* divider (as for the rationale fraction representation), data
* power and the rational fraction divider leftover. Then all of
* this is collected in a total sum variable, which value is
Annotation
- Immediate include surface: `linux/export.h`, `linux/math.h`, `linux/module.h`, `linux/polynomial.h`.
- Detected declarations: `function polynomial_calc`, `export polynomial_calc`.
- 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.