about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--022arithmetic.cc12
-rw-r--r--081print.mu21
-rw-r--r--html/022arithmetic.cc.html12
-rw-r--r--html/081print.mu.html21
4 files changed, 66 insertions, 0 deletions
diff --git a/022arithmetic.cc b/022arithmetic.cc
index 23f9a39d..dfd3b149 100644
--- a/022arithmetic.cc
+++ b/022arithmetic.cc
@@ -714,6 +714,18 @@ def main [
 ]
 +mem: storing 12 in location 1
 
+:(scenario round_halves_toward_zero)
+def main [
+  1:num <- round 12.5
+]
++mem: storing 12 in location 1
+
+:(scenario round_halves_toward_zero_2)
+def main [
+  1:num <- round -12.5
+]
++mem: storing -12 in location 1
+
 :(before "End Primitive Recipe Declarations")
 CHARACTER_TO_CODE,
 :(before "End Primitive Recipe Numbers")
diff --git a/081print.mu b/081print.mu
index adda5db9..9eecf6d3 100644
--- a/081print.mu
+++ b/081print.mu
@@ -106,11 +106,13 @@ def print screen:&:screen, c:char -> screen:&:screen [
   height:num <- get *screen, num-rows:offset
   # if cursor is out of bounds, silently exit
   row:num <- get *screen, cursor-row:offset
+  row <- round row
   legal?:bool <- greater-or-equal row, 0
   return-unless legal?
   legal? <- lesser-than row, height
   return-unless legal?
   column:num <- get *screen, cursor-column:offset
+  column <- round column
   legal? <- greater-or-equal column, 0
   return-unless legal?
   legal? <- lesser-than column, width
@@ -185,6 +187,25 @@ scenario print-character-at-top-left [
   ]
 ]
 
+scenario print-character-at-fractional-coordinate [
+  local-scope
+  fake-screen:&:screen <- new-fake-screen 3/width, 2/height
+  a:char <- copy 97/a
+  run [
+    move-cursor fake-screen, 0.5, 0
+    fake-screen <- print fake-screen, a:char
+    cell:&:@:screen-cell <- get *fake-screen, data:offset
+    1:@:screen-cell/raw <- copy *cell
+  ]
+  memory-should-contain [
+    1 <- 6  # width*height
+    2 <- 97  # 'a'
+    3 <- 7  # white
+    # rest of screen is empty
+    4 <- 0
+  ]
+]
+
 scenario print-character-in-color [
   local-scope
   fake-screen:&:screen <- new-fake-screen 3/width, 2/height
diff --git a/html/022arithmetic.cc.html b/html/022arithmetic.cc.html
index 4d2b454e..b18bc7d2 100644
--- a/html/022arithmetic.cc.html
+++ b/html/022arithmetic.cc.html
@@ -750,6 +750,18 @@ put<span class="Delimiter">(</span>Recipe_ordinal<span class="Delimiter">,</span
 ]
 <span class="traceContains">+mem: storing 12 in location 1</span>
 
+<span class="Delimiter">:(scenario round_halves_toward_zero)</span>
+<span class="muRecipe">def</span> main [
+  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>round <span class="Constant">12.5</span>
+]
+<span class="traceContains">+mem: storing 12 in location 1</span>
+
+<span class="Delimiter">:(scenario round_halves_toward_zero_2)</span>
+<span class="muRecipe">def</span> main [
+  <span class="Constant">1</span>:num<span class="Special"> &lt;- </span>round -<span class="Constant">12.5</span>
+]
+<span class="traceContains">+mem: storing -12 in location 1</span>
+
 <span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
 CHARACTER_TO_CODE<span class="Delimiter">,</span>
 <span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
diff --git a/html/081print.mu.html b/html/081print.mu.html
index 241cf857..5214e80c 100644
--- a/html/081print.mu.html
+++ b/html/081print.mu.html
@@ -141,11 +141,13 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   height:num <span class="Special">&lt;-</span> get *screen, <span class="Constant">num-rows:offset</span>
   <span class="Comment"># if cursor is out of bounds, silently exit</span>
   row:num <span class="Special">&lt;-</span> get *screen, <span class="Constant">cursor-row:offset</span>
+  row <span class="Special">&lt;-</span> round row
   legal?:bool <span class="Special">&lt;-</span> greater-or-equal row,<span class="Constant"> 0</span>
   <span class="muControl">return-unless</span> legal?
   legal? <span class="Special">&lt;-</span> lesser-than row, height
   <span class="muControl">return-unless</span> legal?
   column:num <span class="Special">&lt;-</span> get *screen, <span class="Constant">cursor-column:offset</span>
+  column <span class="Special">&lt;-</span> round column
   legal? <span class="Special">&lt;-</span> greater-or-equal column,<span class="Constant"> 0</span>
   <span class="muControl">return-unless</span> legal?
   legal? <span class="Special">&lt;-</span> lesser-than column, width
@@ -220,6 +222,25 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   ]
 ]
 
+<span class="muScenario">scenario</span> print-character-at-fractional-coordinate [
+  <span class="Constant">local-scope</span>
+  fake-screen:&amp;:screen <span class="Special">&lt;-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
+  a:char <span class="Special">&lt;-</span> copy <span class="Constant">97/a</span>
+  run [
+    move-cursor fake-screen, 0.5,<span class="Constant"> 0</span>
+    fake-screen <span class="Special">&lt;-</span> print fake-screen, a:char
+    cell:&amp;:@:screen-cell <span class="Special">&lt;-</span> get *fake-screen, <span class="Constant">data:offset</span>
+    1:@:screen-cell/<span class="Special">raw</span> <span class="Special">&lt;-</span> copy *cell
+  ]
+  memory-should-contain [
+   <span class="Constant"> 1</span> <span class="Special">&lt;-</span><span class="Constant"> 6</span>  <span class="Comment"># width*height</span>
+   <span class="Constant"> 2</span> <span class="Special">&lt;-</span><span class="Constant"> 97</span>  <span class="Comment"># 'a'</span>
+   <span class="Constant"> 3</span> <span class="Special">&lt;-</span><span class="Constant"> 7</span>  <span class="Comment"># white</span>
+    <span class="Comment"># rest of screen is empty</span>
+   <span class="Constant"> 4</span> <span class="Special">&lt;-</span><span class="Constant"> 0</span>
+  ]
+]
+
 <span class="muScenario">scenario</span> print-character-in-color [
   <span class="Constant">local-scope</span>
   fake-screen:&amp;:screen <span class="Special">&lt;-</span> new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span>
19:15:57 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-08-06 19:15:57 -0700 1949' href='/akkartik/mu/commit/html/034call.cc.html?h=main&id=eaeb955212eb3b133fd98d98457f17bfea8891d1'>eaeb9552 ^
672e3e50 ^
d5d908dd ^
c5ffb6e1 ^



672e3e50 ^
eaeb9552 ^
672e3e50 ^

eaeb9552 ^
672e3e50 ^

d5d908dd ^
eaeb9552 ^

672e3e50 ^

d5d908dd ^
65361948 ^
672e3e50 ^




c5ffb6e1 ^
eaeb9552 ^
65361948 ^

672e3e50 ^

eaeb9552 ^
65361948 ^

672e3e50 ^

eaeb9552 ^
65361948 ^

672e3e50 ^


eaeb9552 ^
672e3e50 ^
eaeb9552 ^
4fe9f5e8 ^



672e3e50 ^
65361948 ^
eaeb9552 ^
c5ffb6e1 ^

672e3e50 ^


4fe9f5e8 ^









eaeb9552 ^
4fe9f5e8 ^


672e3e50 ^


eaeb9552 ^
672e3e50 ^


eaeb9552 ^
65361948 ^

672e3e50 ^




eaeb9552 ^
d5d908dd ^
c5ffb6e1 ^
9542bb11 ^
65361948 ^
eaeb9552 ^
d5d908dd ^
83fcebf3 ^
672e3e50 ^




eaeb9552 ^
672e3e50 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179