frc - Fraction module

Module Description

The frc module implements words for using fractions. 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.

Module Words

Fraction structure

frc% ( - n )
Get the required space for the frc data structure

Structure creation, initialisation and destruction

frc-init ( w:frc - )
Initialise the fraction to zero

frc-create ( "name" - )
Create a named fraction in the dictionary

frc-new ( - w:frc )
Create a new fraction on the heap

frc-free ( w:frc - )
Free the fraction from the heap

General module words

frc+calc-gcd ( n1 n2 - n:gcd )
Calculate the Greatest Common Divider

frc+calc-lcm ( n1 n2 - n:lcm )
Calculate the Least Common Multiplier

frc+norm ( n:num n:denom - n:num n:denom )
Normalize a fraction on stack

Calculation module words

frc+add ( n:num2 n:denom2 n:num1 n:denom1 - n:num n:denom )
Add two fractions on stack

frc+subtract ( n:num2 n:denom2 n:num1 n:denom1 - n:num n:denom )
Subtract fraction1 from fraction2 on stack

frc+multiply ( n:num2 n:denom2 n:num1 n:denom1 - n:num n:denom )
Multiply fraction1 by fraction2 on stack

frc+divide ( n:num2 n:denom2 n:num1 n:denom1 - n:num n:denom )
Divide fraction1 by fraction2 on stack

frc+invert ( n:num n:denom - n:num n:denom )
Invert the fraction on stack

frc+negate ( n:num n:denom - n:num n:denom )
Negate the fraction on stack

frc+abs ( n:num n:denom - n:denom n:num )
Absolute the fraction on stack

Conversion module words

frc+to-float ( n:num n:denom - r )
Convert fraction to float value

frc+to-string ( n:num n:denom - c-addr u )
Convert fraction to a string using the pictured output area

Compare module words

frc+compare ( n:num2 n:denom2 n:num1 n:denom1 - n )
Compare two fractions on stack

Structure words

frc-num@ ( w:frc - n:numerator )
Get the numerator

frc-denom@ ( w:frc - n:denominator )
Get the denominator

frc-get ( w:frc - n:num n:denom )
Get the fraction

frc-set ( n:num n:denom w:frc )
Normalize and set the fraction

frc^move ( w:frc2 w:frc1 - )
Move frc2 in frc1

frc^compare ( w:frc2 w:frc1 - n )
Compare fraction2 with fraction1

Inspection

frc-dump ( w:frc - )
Dump the fraction


generated 09-Jan-2007 by ofcfrth-0.2.0