]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2010-2014 Intel Corporation | |
7c673cae FG |
3 | */ |
4 | ||
5 | #ifndef __INCLUDE_RTE_APPROX_H__ | |
6 | #define __INCLUDE_RTE_APPROX_H__ | |
7 | ||
8 | #ifdef __cplusplus | |
9 | extern "C" { | |
10 | #endif | |
11 | ||
12 | /** | |
13 | * @file | |
14 | * RTE Rational Approximation | |
15 | * | |
16 | * Given a rational number alpha with 0 < alpha < 1 and a precision d, the goal | |
17 | * is to find positive integers p, q such that alpha - d < p/q < alpha + d, and | |
18 | * q is minimal. | |
19 | * | |
20 | ***/ | |
21 | ||
22 | #include <stdint.h> | |
23 | ||
24 | /** | |
25 | * Find best rational approximation | |
26 | * | |
27 | * @param alpha | |
28 | * Rational number to approximate | |
29 | * @param d | |
30 | * Precision for the rational approximation | |
31 | * @param p | |
32 | * Pointer to pre-allocated space where the numerator of the rational | |
33 | * approximation will be stored when operation is successful | |
34 | * @param q | |
35 | * Pointer to pre-allocated space where the denominator of the rational | |
36 | * approximation will be stored when operation is successful | |
37 | * @return | |
38 | * 0 upon success, error code otherwise | |
39 | */ | |
40 | int rte_approx(double alpha, double d, uint32_t *p, uint32_t *q); | |
41 | ||
42 | #ifdef __cplusplus | |
43 | } | |
44 | #endif | |
45 | ||
46 | #endif /* __INCLUDE_RTE_APPROX_H__ */ |