rational.c (c95baf12f5077419db01313ab61c2aac007d40cd) rational.c (d89775fc929c5a1d91ed518a71b456da0865e5ff)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * rational fractions
4 *
5 * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <oskar@scara.com>
6 * Copyright (C) 2019 Trent Piepho <tpiepho@gmail.com>
7 *
8 * helper functions when coping with rational numbers

--- 13 unchanged lines hidden (view full) ---

22 *
23 * rational_best_approximation(31415, 10000,
24 * (1 << 8) - 1, (1 << 5) - 1, &n, &d);
25 *
26 * you may look at given_numerator as a fixed point number,
27 * with the fractional part size described in given_denominator.
28 *
29 * for theoretical background, see:
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * rational fractions
4 *
5 * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <oskar@scara.com>
6 * Copyright (C) 2019 Trent Piepho <tpiepho@gmail.com>
7 *
8 * helper functions when coping with rational numbers

--- 13 unchanged lines hidden (view full) ---

22 *
23 * rational_best_approximation(31415, 10000,
24 * (1 << 8) - 1, (1 << 5) - 1, &n, &d);
25 *
26 * you may look at given_numerator as a fixed point number,
27 * with the fractional part size described in given_denominator.
28 *
29 * for theoretical background, see:
30 * http://en.wikipedia.org/wiki/Continued_fraction
30 * https://en.wikipedia.org/wiki/Continued_fraction
31 */
32
33void rational_best_approximation(
34 unsigned long given_numerator, unsigned long given_denominator,
35 unsigned long max_numerator, unsigned long max_denominator,
36 unsigned long *best_numerator, unsigned long *best_denominator)
37{
38 /* n/d is the starting rational, which is continually

--- 64 unchanged lines hidden ---
31 */
32
33void rational_best_approximation(
34 unsigned long given_numerator, unsigned long given_denominator,
35 unsigned long max_numerator, unsigned long max_denominator,
36 unsigned long *best_numerator, unsigned long *best_denominator)
37{
38 /* n/d is the starting rational, which is continually

--- 64 unchanged lines hidden ---