Module:JI ratio finder: Difference between revisions
m Clarified int limit for candidate ratio search (it's a denominator limit, not an int limit) |
Added prime limit to candidate ratio search (default is 97) |
||
| Line 25: | Line 25: | ||
-- Finds candidate ratios up to a cent value and up to an integer limit that | -- Finds candidate ratios up to a cent value and up to an integer limit that | ||
-- applies to the denominator only. | -- applies to the denominator only, and within a prime limit. | ||
-- Ratios found this way will range from 0 cents to the given cent value. | -- Ratios found this way will range from 0 cents to the given cent value. | ||
-- These ratios should then be filtered as needed. | -- These ratios should then be filtered as needed. | ||
function p.find_candidate_ratios(cents, denominator_limit) | function p.find_candidate_ratios(cents, denominator_limit, prime_limit) | ||
local cents = cents or 1200 | local cents = cents or 1200 | ||
local denominator_limit = denominator_limit or 99 | local denominator_limit = denominator_limit or 99 | ||
local prime_limit = prime_limit or 97 | |||
local candidate_ratios = {} | local candidate_ratios = {} | ||
| Line 42: | Line 43: | ||
local current_ratio = rat.new(numerator, denominator) | local current_ratio = rat.new(numerator, denominator) | ||
local is_simplified = utils._gcd(numerator, denominator) == 1 | local is_simplified = utils._gcd(numerator, denominator) == 1 | ||
local is_within_prime_limit = rat.max_prime(current_ratio) | |||
is_within_cents = rat.cents(current_ratio) <= cents | is_within_cents = rat.cents(current_ratio) <= cents | ||