randRange( 1, 10 ) randRange( 1, 30 ) randRange( 1, 30 ) M_NUM / getGCD( M_NUM, M_DENOM ) M_DENOM / getGCD( M_NUM, M_DENOM ) WHOLE * M_REDUCED_DENOM + M_REDUCED_NUM M_REDUCED_DENOM

Convert fraction( I_NUM, I_DENOM, false, true ) to a mixed number.

I_NUM / I_DENOM

First, divide the numerator by the denominator.

I_NUM \div I_DENOM = \color{#28AE7B}{WHOLE}\ \text{ R } \color{purple}{M_REDUCED_NUM}

So the improper fraction has WHOLE wholes in it, which is equal to \color{#28AE7B}{WHOLE} \times \dfrac{I_DENOM}{I_DENOM} = \color{#28AE7B}{fraction( I_DENOM * WHOLE, I_DENOM, false, false )}.

init({ range: [ [0, 1], [0, WHOLE] ], scale: [250, 25] }); for ( var y = 0; y < WHOLE; y++ ) { rectchart( [M_REDUCED_DENOM, 0], ["#28AE7B", "#999"], y ); }

This quotient WHOLE is the whole number part of the mixed number.

We also have a remainder of M_REDUCED_NUM, though. That represents the \dfrac{\color{purple}{M_REDUCED_NUM}}{I_DENOM} remaining from the improper fraction; it wasn't enough to be another whole number.

init({ range: [ [0, 1], [0, 1] ], scale: [250, 25] }); rectchart( [M_REDUCED_NUM, M_REDUCED_DENOM - M_REDUCED_NUM], ["purple", "#999"] );

The converted mixed fraction is \color{#28AE7B}{WHOLE}\ \color{purple}{fraction( M_NUM, M_DENOM, false, true )}.

init({ range: [ [0, 1], [0, WHOLE + 1] ], scale: [250, 25] }); for ( var y = 1; y <= WHOLE; y++ ) { rectchart( [M_REDUCED_DENOM, 0], ["#28AE7B", "#999"], y ); } rectchart( [M_REDUCED_NUM, M_REDUCED_DENOM - M_REDUCED_NUM], ["purple", "#999"] );

Note that if we add up the two pieces of our mixed fraction, \color{#28AE7B}{fraction( I_DENOM * WHOLE, I_DENOM, false, false )} + \color{purple}{fraction( M_NUM, M_DENOM, false, true )}, we get the original improper fraction fraction( I_NUM, I_DENOM, false, true ).

Convert WHOLE\ fraction( M_NUM, M_DENOM, false, true ) to an improper fraction.

I_NUM / I_DENOM

\color{#FFA500}{WHOLE}\ \color{#6495ED}{fraction( M_NUM, M_DENOM, false, true )}

This mixed number is equivalent to \color{#FFA500}{WHOLE} + \color{#6495ED}{fraction( M_NUM, M_DENOM, false, true )}.

First, convert the whole part of the mixed number to a fraction with the same denominator M_REDUCED_DENOM as the fractional part.

\color{#FFA500}{WHOLE} \times \dfrac{M_REDUCED_DENOM}{M_REDUCED_DENOM} = \color{#FFA500}{\dfrac{WHOLE * M_REDUCED_DENOM}{M_REDUCED_DENOM}}

init({ range: [ [0, 1], [0, WHOLE] ], scale: [250, 25] }); for ( var y = 0; y < WHOLE; y++ ) { rectchart( [M_REDUCED_DENOM, 0], ["#FFA500", "#999"], y ); }

So now we have our number in the form \color{#FFA500}{\dfrac{WHOLE * M_REDUCED_DENOM}{M_REDUCED_DENOM}} + \color{#6495ED}{fraction( M_NUM, M_DENOM, false, true )}.

init({ range: [ [0, 1], [0, WHOLE + 1] ], scale: [250, 25] }); for ( var y = 1; y <= WHOLE; y++ ) { rectchart( [M_REDUCED_DENOM, 0], ["#FFA500", "#999"], y ); } rectchart( [M_REDUCED_NUM, M_REDUCED_DENOM - M_REDUCED_NUM], ["#6495ED", "#999"] );

Now, just add the two fractions and simplify!

\color{#FFA500}{\dfrac{WHOLE * M_REDUCED_DENOM}{M_REDUCED_DENOM}} + \color{#6495ED}{fraction( M_NUM, M_DENOM, false, true )} = fraction( I_NUM, I_DENOM, true, true )