160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
end
terra m.decstr(val: intptr, buf: &int8): rawstring
-- works backwards to avoid copies. log10(2^64) ≈ 19.2 and we
-- need a byte for NUL so buf MUST point to THE END OF a buffer
-- at least 21 bytes long
@buf = 0
if val > 0 then while val > 0 do
buf = buf - 1
var dgt = val % 10
val = val / 10
@buf = 0x30 + dgt
end else
buf = buf - 1
@buf = 0x30
end
return buf
end
terra m.decstr_friendly(val: intptr, buf: &int8): rawstring
|
>
|
|
|
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
end
terra m.decstr(val: intptr, buf: &int8): rawstring
-- works backwards to avoid copies. log10(2^64) ≈ 19.2 and we
-- need a byte for NUL so buf MUST point to THE END OF a buffer
-- at least 21 bytes long
@buf = 0
if val ~= 0 then
while val > 0 do
buf = buf - 1
var dgt = val % 10
val = val / 10
@buf = 0x30 + dgt
end
else
buf = buf - 1
@buf = 0x30
end
return buf
end
terra m.decstrs(inval: ptrdiff, buf: &int8): rawstring
-- works backwards to avoid copies. log10(2^64) ≈ 19.2 and we
-- need a byte for NUL so buf MUST point to THE END OF a buffer
-- at least 22 bytes long
@buf = 0
var val = inval
if val ~= 0 then
if val < 0 then
val = -val
end
while val > 0 do
buf = buf - 1
var dgt = val % 10
val = val / 10
@buf = 0x30 + dgt
end
if inval < 0 then
buf = buf - 1
@buf = @"-"
end
else
buf = buf - 1
@buf = 0x30
end
return buf
end
terra m.decstr_friendly(val: intptr, buf: &int8): rawstring
|