Skip to main content


I've made a fraction-based calculator, for simplifying rational expressions (written in ANSI-C using vi)

I was aiming to merge a scientific calculator with "bc", because I often need to simplify various fractions and whatnot. Quite happy with the result!

Uses shunting yard algorithm to evaluate the expressions, and a naive descent parser (I think?) to tokenise

Aside: OpenBSD's "editline" is very easy to use

Please ask any questions 😀

http://patpatpat.xyz/data/frac

#c #bsd #unix #math

#math #unix #BSD #C
This entry was edited (1 week ago)
in reply to Pat

That's such a nice idea, I went through the same motion for my own calculator, there's some interesting operators you can do with this, like to swap the numerator and denumerator, or break them back into their individual digits:

I've named the reverse of a division, vidision.

in reply to Devine Lu Linvega

@neauoire Ooh that is very cool, it really shows off how great stacks are as a construct. Its quite fun that a good way of performing infix maths is just to convert it to RPN

Mixed-fractions, decimal/fraction conversion, and some misc functions are on the TODO list in my head. I probably also need to add variables, as currently the result is just printed out?

I actually just treat everything as a fraction, so there's not really a concept of separate digits. Its all just reciprocals

in reply to Pat

it'll be nice to see it evolve. Being able to turn 2/3 into 2/1 and 3/1 is a pretty nice feature, variables will be nice too!

Lo, thar be cookies on this site to keep track of your login. By clicking 'okay', you are CONSENTING to this.