{"id":"fraction-to-decimal-expand","version":"1.0.0","description":"Expand an integer fraction into its exact decimal with the minimal repeating block marked, e.g. 1/7 as 0.(142857).","supported_operations":["convert fraction to repeating decimal","what is 1/7 as a decimal","find the repeating block of a fraction","period length of 1/97","does this fraction terminate or repeat","long division of a fraction to decimal digits","non repeating prefix and repeating part of n over d","expand a fraction with recurring digits"],"unsupported_operations":["converting decimals or repeating decimals to fractions","rounding a fraction to a fixed number of places","mixed numbers, continued fractions or percentages","fractions with more than 40 digit integers"],"semantics":["numerator and denominator are decimal integer strings matching ^-?(0|[1-9][0-9]*)$ with at most 40 digits. A JSON number, a fraction sign, a plus sign, leading zeros, a point, whitespace or more than 40 digits is invalid_input (this is invalid_input, not limit_exceeded, even for a very long digit string).","denominator 0 -> not_computable with details.reason \"division_by_zero\", including 0/0. This is checked after all field validation.","Reduce the fraction to lowest terms first. Only the reduced denominator matters: 24027/56063 is 3/7 and expands as 0.(428571); 8009/16018 is 1/2 and expands as 0.5.","The sign is negative exactly when numerator and denominator have different signs and the numerator is not zero. Zero has no sign: 0/5, -0/5 and 0/-5 give \"0\" with negative false. -3/-6 is +0.5.","The reduced denominator is 2^a * 5^b * m with gcd(m,10) = 1. The non-repeating prefix has max(a,b) digits; the repeating block has length equal to the multiplicative order of 10 modulo m (0 when m = 1). 1/28 = 0.03(571428): prefix \"03\" (2 digits from 4 = 2^2), block of 6 (order of 10 mod 7).","Standard long division with remainder tracking: the block starts at the first position whose remainder recurs. The block is the minimal period, never a multiple of it, and never the block \"0\" or \"9\". 1/3 is 0.(3), never 0.(33) and never 0.333; 1/2 is 0.5, never 0.5(0) or 0.4(9).","notation is \"[-]\" + integer_part, then, when there is a non-empty prefix or block, \".\" + non_repeating + \"(\" + repeating + \")\" (the parenthesised part only when repeating is non-empty). An integer result has no point: 10/2 gives \"5\", -10/2 gives \"-5\". Exactly: 1/6 gives \"0.1(6)\"; 22/7 gives \"3.(142857)\"; 1/8 gives \"0.125\".","integer_part is floor(|n|/d) as a digit string without sign or leading zeros (\"0\" when |n| < d). period_length is the length of repeating (0 when terminating). terminating is true iff repeating is empty.","Period limit: a reduced denominator whose period exceeds 2000 digits -> limit_exceeded, checked after the division-by-zero check and after reduction. A period of exactly 2000 succeeds (1/16001 has period 2000; 1/8009 has period 2002 and is rejected). The check depends only on the period, not on the size of the prefix or numerator.","Validation order: input not an object; unknown field; missing field; field types and integer grammar and digit limits; then division_by_zero; then the period limit."],"limits":{"max_integer_digits":40,"max_period":2000,"max_non_repeating_digits":132},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["numerator","denominator"],"properties":{"numerator":{"type":"string","minLength":1,"maxLength":41,"pattern":"^-?(0|[1-9][0-9]*)$","description":"Integer numerator as a decimal integer string, at most 40 digits."},"denominator":{"type":"string","minLength":1,"maxLength":41,"pattern":"^-?(0|[1-9][0-9]*)$","description":"Integer denominator as a decimal integer string, at most 40 digits; zero -> not_computable."}}},"output_schema":{"type":"object","additionalProperties":false,"required":["notation","integer_part","non_repeating","repeating","period_length","terminating","negative"],"properties":{"notation":{"type":"string","minLength":1,"maxLength":2300,"description":"Canonical text: [-]int, then [.non_repeating] and, when the expansion repeats, (repeating) in parentheses."},"integer_part":{"type":"string","minLength":1,"maxLength":40,"description":"Digits before the point, without sign."},"non_repeating":{"type":"string","maxLength":140,"description":"Fraction digits before the repeating block; may be empty."},"repeating":{"type":"string","maxLength":2000,"description":"The repeating block; empty when the expansion terminates."},"period_length":{"type":"integer","minimum":0,"maximum":2000,"description":"Length of the repeating block; 0 when the expansion terminates."},"terminating":{"type":"boolean","description":"true when the expansion terminates (no repeating block)."},"negative":{"type":"boolean","description":"true when the fraction is below zero."}}},"examples":[{"input":{"numerator":"1","denominator":"7"},"output":{"notation":"0.(142857)","integer_part":"0","non_repeating":"","repeating":"142857","period_length":6,"terminating":false,"negative":false}},{"input":{"numerator":"1","denominator":"28"},"output":{"notation":"0.03(571428)","integer_part":"0","non_repeating":"03","repeating":"571428","period_length":6,"terminating":false,"negative":false}},{"input":{"numerator":"-10","denominator":"4"},"output":{"notation":"-2.5","integer_part":"2","non_repeating":"5","repeating":"","period_length":0,"terminating":true,"negative":true}}],"execute_url":"/v1/tools/fraction-to-decimal-expand/versions/1.0.0/execute"}