Module description

frc -- Fraction module
The frc module implements a fraction data type. Note: to reduce normalizing of fractions, the input is validated and normalized, but the resulting output is NOT normalized. This is left to the next fraction word.

Fraction structure

frc% ( -- n )
Get the required space for a frc variable

Fraction creation, initialisation and destruction

frc-init ( frc -- )
Initialise the fraction to zero
frc-create ( "<spaces>name" -- ; -- frc )
Create a named fraction in the dictionary
frc-new ( -- frc )
Create a new fraction on the heap
frc-free ( frc -- )
Free the fraction from the heap

General module words

frc+calc-gcd ( n1 n2 -- +n )
Calculate the Greatest Common Divider
frc+calc-lcm ( n1 n2 -- +n )
Calculate the Least Common Multiplier
frc+norm ( n1 n2 -- n3 n4 )
Normalize a fraction n1/n2, return n3/n4

Calculation module words

frc+add ( n1 n2 n3 n4 -- n5 n6 )
Add two fractions n1/n2 and n3/n4, return n5/n6
frc+subtract ( n1 n2 n3 n4 -- n5 n6 )
Subtract fraction n3/n4 from fraction n1/n2, return n5/n6
frc+multiply ( n1 n2 n3 n4 -- n5 n6 )
Multiply fraction n1/n2 by fraction n3/n4, return n5/n6
frc+divide ( n1 n2 n3 n4 -- n5 n6 )
Divide fraction n1/n2 by fraction n3/n4, return n5/n6
frc+invert ( n1 n2 -- n3 n4 )
Invert the fraction n1/n2, return n3/n4
frc+negate ( n1 n2 -- n3 n4 )
Negate the fraction n1/n2, return n3/n4
frc+abs ( n1 n2 -- n3 n4 )
Absolute the fraction n1/n2, return n3/n4

Conversion module words

frc+to-float ( n1 n2 -- r )
Convert fraction n1/n2 to float value
frc+to-string ( n1 n2 -- c-addr u )
Convert fraction n1/n2 to a string using the pictured output area

Compare module words

frc+compare ( n1 n2 n3 n4 -- n )
Compare the fractions n1/n2 and n3/n4, return the result [-1,0,1]

Structure words

frc-num@ ( frc -- n )
Get the numerator
frc-denom@ ( frc -- n )
Get the denominator
frc-get ( frc -- n1 n2 )
Get the fraction n1/n2
frc-set ( n1 n2 frc )
Normalize and set the fraction n1/n2
frc^move ( frc2 frc1 -- )
Move frc2 in frc1
frc^compare ( frc2 frc1 -- n )
Compare fraction2 with fraction1, return the result [-1,0,1]

Inspection

frc-dump ( frc -- )
Dump the fraction

Generated by fsdocgen 0.1.0