diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-12 18:08:47 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-12 18:08:47 -0700 |
commit | fca0ebbe0cc01d37e47822d8a62ea062a845f33d (patch) | |
tree | 557ef7d0bd5d3ddc98ab47cf0273c99cc4a09630 /021arithmetic.cc | |
parent | 98f3a94201df11501d417ac2e75a756ab54ac873 (diff) | |
download | mu-fca0ebbe0cc01d37e47822d8a62ea062a845f33d.tar.gz |
1360 - store doubles in memory
This is a far cleaner way to provide *some* floating-point support. We can only represent signed integers up to 2^51 rather than 2^63. But in exchange we don't have to worry about it elsewhere, and it's probably faster than checking tag bits in every operation. Hmm, yeah, surprised how easy this was. I think I'll give up on the other approach. I still don't have non-integer literals. But we won't bother with those until we need them. `3.14159:literal` seems ugly.
Diffstat (limited to '021arithmetic.cc')
-rw-r--r-- | 021arithmetic.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/021arithmetic.cc b/021arithmetic.cc index 307bcb18..0dedd02d 100644 --- a/021arithmetic.cc +++ b/021arithmetic.cc @@ -6,7 +6,7 @@ ADD, Recipe_number["add"] = ADD; :(before "End Primitive Recipe Implementations") case ADD: { - long long int result = 0; + double result = 0; for (index_t i = 0; i < ingredients.size(); ++i) { assert(ingredients.at(i).size() == 1); // scalar result += ingredients.at(i).at(0); @@ -53,7 +53,7 @@ Recipe_number["subtract"] = SUBTRACT; :(before "End Primitive Recipe Implementations") case SUBTRACT: { assert(ingredients.at(0).size() == 1); // scalar - long long int result = ingredients.at(0).at(0); + double result = ingredients.at(0).at(0); for (index_t i = 1; i < ingredients.size(); ++i) { assert(ingredients.at(i).size() == 1); // scalar result -= ingredients.at(i).at(0); @@ -99,7 +99,7 @@ MULTIPLY, Recipe_number["multiply"] = MULTIPLY; :(before "End Primitive Recipe Implementations") case MULTIPLY: { - long long int result = 1; + double result = 1; for (index_t i = 0; i < ingredients.size(); ++i) { assert(ingredients.at(i).size() == 1); // scalar result *= ingredients.at(i).at(0); @@ -146,7 +146,7 @@ Recipe_number["divide"] = DIVIDE; :(before "End Primitive Recipe Implementations") case DIVIDE: { assert(ingredients.at(0).size() == 1); // scalar - long long int result = ingredients.at(0).at(0); + double result = ingredients.at(0).at(0); for (index_t i = 1; i < ingredients.size(); ++i) { assert(ingredients.at(i).size() == 1); // scalar result /= ingredients.at(i).at(0); @@ -193,7 +193,7 @@ Recipe_number["divide-with-remainder"] = DIVIDE_WITH_REMAINDER; :(before "End Primitive Recipe Implementations") case DIVIDE_WITH_REMAINDER: { long long int quotient = ingredients.at(0).at(0) / ingredients.at(1).at(0); - long long int remainder = ingredients.at(0).at(0) % ingredients.at(1).at(0); + long long int remainder = static_cast<long long int>(ingredients.at(0).at(0)) % static_cast<long long int>(ingredients.at(1).at(0)); products.resize(2); products.at(0).push_back(quotient); products.at(1).push_back(remainder); @@ -227,3 +227,10 @@ recipe main [ +mem: storing 2 in location 3 +run: product 1 is 4 +mem: storing 5 in location 4 + +:(scenario divide_with_decimal_point) +recipe main [ + # todo: literal floats? + 1:integer <- divide 5:literal, 2:literal +] ++mem: storing 2.5 in location 1 |