Postfix calculator, written in ANSI C
Minor cleanup
Replaced string parsing with scanf
Removed logic examples for readme


browse  log 



You can also use your local clone with git send-email.


A postfix calculator with fractions, written in ANSI C.


cc 1th.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -o 1th


The supported operations are as follow:


  • . Print fraction
  • std Standard(default)
  • mix Mixed
  • dec Decimal
  • hex Hexadecimal
  • bin Binary


  • clr Discards stack
  • pop Discards the top stack item
  • swp Reverses the top two stack items
  • dup Duplicates the top stack item
  • ovr Copies second item to top
  • rot Rotates third item to top


  • add, or +
  • sub, or -
  • mul, or *
  • div, or /
  • mod, or %


  • and, or &
  • or, or |
  • xor, or ^
  • rol, or <<
  • ror, or >>


  • inv Invert numerator and denominator
  • vid Convert fraction to two whole numbers


The following example, will print the result 3&1/6.

clr 11 4 div 5 12 div add _

To get the floor of a fraction.

clr 17 4 div dup 1 mod sub .

To round a the fraction -12/8.

clr 0 12 sub 8 div dup dup 1 mod sub swp dup vid swp pop swp vid mod 2 mul swp div dup 1 mod sub add .


  • The Numerator is the top of part of a fraction.
  • The Denominator is the bottom of part of a fraction.
  • A Proper Fraction has a numerator that is smaller than its denominator and represents a quantity less than the whole.
  • An Improper Fraction has a numerator larger than its denominator and represents a quantity greater than the whole.
  • Mixed Numbers are whole numbers and portions less than 1 added together, like 2 3/4.
  • Like Fractions are fractions with the same denominators.
  • Unlike Fractions are fractions with different denominators.
  • A Reciprocal is the inverted value of a fraction, like 12/34 is the reciprocal of 34/12.