about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--022arithmetic.cc14
-rw-r--r--070table.mu4
-rw-r--r--html/022arithmetic.cc.html14
-rw-r--r--html/070table.mu.html4
4 files changed, 18 insertions, 18 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc
index f46666f1..23f9a39d 100644
--- a/022arithmetic.cc
+++ b/022arithmetic.cc
@@ -269,8 +269,9 @@ case DIVIDE_WITH_REMAINDER: {
 :(before "End Primitive Recipe Implementations")
 case DIVIDE_WITH_REMAINDER: {
   products.resize(2);
-  int a = static_cast<int>(ingredients.at(0).at(0));
-  int b = static_cast<int>(ingredients.at(1).at(0));
+  // fractions will be dropped; very large numbers will overflow
+  long long int a = static_cast<long long int>(ingredients.at(0).at(0));
+  long long int b = static_cast<long long int>(ingredients.at(1).at(0));
   if (b == 0) {
     raise << maybe(current_recipe_name()) << "divide by zero in '" << to_original_string(current_instruction()) << "'\n" << end();
     products.resize(2);
@@ -278,11 +279,10 @@ case DIVIDE_WITH_REMAINDER: {
     products.at(1).push_back(0);
     break;
   }
-  int quotient = a / b;
-  int remainder = a % b;
-  // very large integers will lose precision
-  products.at(0).push_back(quotient);
-  products.at(1).push_back(remainder);
+  long long int quotient = a / b;
+  long long int remainder = a % b;
+  products.at(0).push_back(static_cast<double>(quotient));
+  products.at(1).push_back(static_cast<double>(remainder));
   break;
 }
 
diff --git a/070table.mu b/070table.mu
index d567475c..171bb2a8 100644
--- a/070table.mu
+++ b/070table.mu
@@ -52,7 +52,7 @@ def put-index table:&:table:_key:_value, key:_key, value:_value -> table:&:table
   hash <- abs hash
   capacity:num <- get *table, capacity:offset
   _, hash-key:num <- divide-with-remainder hash, capacity
-  hash-key <- abs hash-key  # in case hash-key overflows into a negative integer
+  hash-key <- abs hash-key  # in case hash overflows from a double into a negative integer inside 'divide-with-remainder' above
   table-data:&:@:table-row:_key:_value <- get *table, data:offset
   x:table-row:_key:_value <- index *table-data, hash-key
   occupied?:bool <- get x, occupied?:offset
@@ -69,7 +69,7 @@ def index table:&:table:_key:_value, key:_key -> result:_value [
   hash <- abs hash
   capacity:num <- get *table, capacity:offset
   _, hash-key:num <- divide-with-remainder hash, capacity
-  hash-key <- abs hash-key  # in case hash-key overflows into a negative integer
+  hash-key <- abs hash-key  # in case hash overflows from a double into a negative integer inside 'divide-with-remainder' above
   table-data:&:@:table-row:_key:_value <- get *table, data:offset
   x:table-row:_key:_value <- index *table-data, hash-key
   occupied?:bool <- get x, occupied?:offset
diff --git a/html/022arithmetic.cc.html b/html/022arithmetic.cc.html
index 7a0e24b9..4d2b454e 100644
--- a/html/022arithmetic.cc.html
+++ b/html/022arithmetic.cc.html
@@ -305,8 +305,9 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 <span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
 <span class="Normal">case</span> DIVIDE_WITH_REMAINDER: <span class="Delimiter">{</span>
   products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span>
-  <span class="Normal">int</span> a = <span class="Normal">static_cast</span>&lt;<span class="Normal">int</span>&gt;<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
-  <span class="Normal">int</span> b = <span class="Normal">static_cast</span>&lt;<span class="Normal">int</span>&gt;<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
+  <span class="Comment">// fractions will be dropped; very large numbers will overflow</span>
+  <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> a = <span class="Normal">static_cast</span>&lt;<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>&gt;<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
+  <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> b = <span class="Normal">static_cast</span>&lt;<span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span>&gt;<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>b == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
     raise &lt;&lt; maybe<span class="Delimiter">(</span>current_recipe_name<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;divide by zero in '&quot;</span> &lt;&lt; to_original_string<span class="Delimiter">(</span>current_instruction<span class="Delimiter">())</span> &lt;&lt; <span class="Constant">&quot;'</span><span class="cSpecial">\n</span><span class="Constant">&quot;</span> &lt;&lt; end<span class="Delimiter">();</span>
     products<span class="Delimiter">.</span>resize<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span>
@@ -314,11 +315,10 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
     products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
     <span class="Identifier">break</span><span class="Delimiter">;</span>
   <span class="Delimiter">}</span>
-  <span class="Normal">int</span> quotient = a / b<span class="Delimiter">;</span>
-  <span class="Normal">int</span> remainder = a % b<span class="Delimiter">;</span>
-  <span class="Comment">// very large integers will lose precision</span>
-  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>quotient<span class="Delimiter">);</span>
-  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span>remainder<span class="Delimiter">);</span>
+  <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> quotient = a / b<span class="Delimiter">;</span>
+  <span class="Normal">long</span> <span class="Normal">long</span> <span class="Normal">int</span> remainder = a % b<span class="Delimiter">;</span>
+  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Normal">static_cast</span>&lt;<span class="Normal">double</span>&gt;<span class="Delimiter">(</span>quotient<span class="Delimiter">));</span>
+  products<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>push_back<span class="Delimiter">(</span><span class="Normal">static_cast</span>&lt;<span class="Normal">double</span>&gt;<span class="Delimiter">(</span>remainder<span class="Delimiter">));</span>
   <span class="Identifier">break</span><span class="Delimiter">;</span>
 <span class="Delimiter">}</span>
 
diff --git a/html/070table.mu.html b/html/070table.mu.html
index 7d46ec53..b843f50f 100644
--- a/html/070table.mu.html
+++ b/html/070table.mu.html
@@ -86,7 +86,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   hash <span class="Special">&lt;-</span> abs hash
   capacity:num <span class="Special">&lt;-</span> get *table, <span class="Constant">capacity:offset</span>
   _, hash-key:num <span class="Special">&lt;-</span> divide-with-remainder hash, capacity
-  hash-key <span class="Special">&lt;-</span> abs hash-key  <span class="Comment"># in case hash-key overflows into a negative integer</span>
+  hash-key <span class="Special">&lt;-</span> abs hash-key  <span class="Comment"># in case hash overflows from a double into a negative integer inside 'divide-with-remainder' above</span>
   table-data:&amp;:@:table-row:_key:_value <span class="Special">&lt;-</span> get *table, <span class="Constant">data:offset</span>
   x:table-row:_key:_value <span class="Special">&lt;-</span> index *table-data, hash-key
   occupied?:bool <span class="Special">&lt;-</span> get x, <span class="Constant">occupied?:offset</span>
@@ -103,7 +103,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   hash <span class="Special">&lt;-</span> abs hash
   capacity:num <span class="Special">&lt;-</span> get *table, <span class="Constant">capacity:offset</span>
   _, hash-key:num <span class="Special">&lt;-</span> divide-with-remainder hash, capacity
-  hash-key <span class="Special">&lt;-</span> abs hash-key  <span class="Comment"># in case hash-key overflows into a negative integer</span>
+  hash-key <span class="Special">&lt;-</span> abs hash-key  <span class="Comment"># in case hash overflows from a double into a negative integer inside 'divide-with-remainder' above</span>
   table-data:&amp;:@:table-row:_key:_value <span class="Special">&lt;-</span> get *table, <span class="Constant">data:offset</span>
   x:table-row:_key:_value <span class="Special">&lt;-</span> index *table-data, hash-key
   occupied?:bool <span class="Special">&lt;-</span> get x, <span class="Constant">occupied?:offset</span>