Skip to content

Integer arithmetic

Latest

Choose a tag to compare

@c0c0n3 c0c0n3 released this 11 Mar 11:43
bd8248d

We keep developing our pocket calculator to make it support any integer arithmetic expression.

Our arithmetic language lets us work with integer arithmetic expressions---a.k.a. arithmetic without fractions. Expressions involve sums, subtractions, products, and divisions among integer values. Since we're only dealing with integers, the result of evaluating an expression should still be an integer. For this reason, x/y is an integer division which returns the quotient q of Euclidean division of x by y---i.e. x = y*q + r, 0 <= r < |y|.

Notice how extending the Expr data type with more cases in the Lang module caused a ripple effect in all the others. This is an instance of the "expression problem" which is a bit too hard to solve with what we know at this stage. But we'll revisit this problem again in a few months from now and put in place a mind-bending solution :-)