RRatioFlint
Workflows

Coding workflows · Canonical rational fractions

03
Built around your work

A concrete starting point

Reduce a fraction of two integers to a positive denominator and coprime terms. Check a negative denominator and a zero numerator, rejecting a zero denominator and non-integer operands before reduction.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Canonical rational fractions

A concrete starting point
from math import gcd

def reduce_fraction(numerator, denominator):
    if any(type(v) is not int for v in (numerator, denominator)):
        raise ValueError("integer.required")
    if denominator == 0:
        raise ValueError("denominator.zero")
    if denominator < 0:
        numerator, denominator = -numerator, -denominator
    divisor = gcd(numerator, denominator)
    return numerator // divisor, denominator // divisor

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗