Replaced string parsing with scanf
Removed logic examples for readme
Added bitwise
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 fractionstd
Standard(default)mix
Mixeddec
Decimalhex
Hexadecimalbin
Binaryclr
Discards stackpop
Discards the top stack itemswp
Reverses the top two stack itemsdup
Duplicates the top stack itemovr
Copies second item to toprot
Rotates third item to topadd
, or +
sub
, or -
mul
, or *
div
, or /
mod
, or %
and
, or &
or
, or |
xor
, or ^
rol
, or <<
ror
, or >>
inv
Invert numerator and denominatorvid
Convert fraction to two whole numbersThe 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 .
2 3/4
.12/34
is the reciprocal of 34/12
.