diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-11-05 21:14:40 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-11-05 21:14:40 -0700 |
commit | 2e57fed3596983b3f8b2fed3694cb50bf4e3eef7 (patch) | |
tree | d917d0ca50ceac70dc601bc561f9e0e1e2192a48 | |
parent | 3badf009dfad5e0847fb88abe0d8251ad72ec1ad (diff) | |
download | mu-2e57fed3596983b3f8b2fed3694cb50bf4e3eef7.tar.gz |
3624 - new rounding instruction: 'truncate'
-rw-r--r-- | 022arithmetic.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc index dfd3b149..9ae5693b 100644 --- a/022arithmetic.cc +++ b/022arithmetic.cc @@ -727,6 +727,41 @@ def main [ +mem: storing -12 in location 1 :(before "End Primitive Recipe Declarations") +TRUNCATE, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "truncate", TRUNCATE); +:(before "End Primitive Recipe Checks") +case TRUNCATE: { + if (SIZE(inst.ingredients) != 1) { + raise << maybe(get(Recipe, r).name) << "'truncate' requires exactly one ingredient, but got '" << inst.original_string << "'\n" << end(); + break; + } + if (!is_mu_number(inst.ingredients.at(0))) { + raise << maybe(get(Recipe, r).name) << "first ingredient of 'truncate' should be a number, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); + break; + } + break; +} +:(before "End Primitive Recipe Implementations") +case TRUNCATE: { + products.resize(1); + products.at(0).push_back(trunc(ingredients.at(0).at(0))); + break; +} + +:(scenario truncate_to_nearest_integer) +def main [ + 1:num <- truncate 12.2 +] ++mem: storing 12 in location 1 + +:(scenario truncate_negative) +def main [ + 1:num <- truncate -12.2 +] ++mem: storing -12 in location 1 + +:(before "End Primitive Recipe Declarations") CHARACTER_TO_CODE, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "character-to-code", CHARACTER_TO_CODE); |