-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathto_string.mbt
More file actions
719 lines (666 loc) · 20.5 KB
/
to_string.mbt
File metadata and controls
719 lines (666 loc) · 20.5 KB
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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///|
#cfg(not(target="js"))
const ALPHABET : String = "0123456789abcdefghijklmnopqrstuvwxyz"
///|
#cfg(not(target="js"))
fn unsafe_fixedarray_uint16_to_string(buffer : FixedArray[UInt16]) -> String = "%string.unsafe_from_uint16_fixedarray"
//==========================================
// Int and UInt (Non JS)
//==========================================
///|
/// Converts an unsigned 32-bit integer to hexadecimal
#cfg(not(target="js"))
fn int_to_string_hex(
buffer : FixedArray[UInt16],
num : UInt,
digit_start : Int,
total_len : Int,
) -> Unit {
// Process 2 hex digits (1 byte) at a time
let (offset, n) = for offset = total_len - digit_start, n = num; offset >= 2; {
let byte_val = n.land(0xFFU).reinterpret_as_int()
let hi = byte_val / 16
let lo = byte_val % 16
buffer.unsafe_set(digit_start + offset - 2, ALPHABET.unsafe_get(hi))
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(lo))
continue offset - 2, n >> 8
} nobreak {
(offset, n)
}
// Handle remaining single hex digit
if offset == 1 {
let nibble = n.land(0xFU).reinterpret_as_int()
buffer.unsafe_set(digit_start, ALPHABET.unsafe_get(nibble))
}
}
///|
/// Generic radix conversion for any base 2-36
#cfg(not(target="js"))
fn int_to_string_generic(
buffer : FixedArray[UInt16],
num : UInt,
digit_start : Int,
total_len : Int,
radix : Int,
) -> Unit {
let base = radix.reinterpret_as_uint()
if (radix & (radix - 1)) == 0 {
// Power-of-two radix: use bit shifts
let shift = radix.ctz()
let mask = base - 1U
for offset = total_len - digit_start, n = num; n > 0U; {
let digit = n.land(mask).reinterpret_as_int()
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(digit))
continue offset - 1, n >> shift
}
} else {
// General radix: use division
for offset = total_len - digit_start, n = num; n > 0U; {
let q = n / base
let digit = (n - q * base).reinterpret_as_int()
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(digit))
continue offset - 1, q
}
}
}
///|
/// Converts an unsigned 32-bit integer to decimal string
#cfg(not(target="js"))
fn int_to_string_dec(
buffer : FixedArray[UInt16],
num : UInt,
digit_start : Int,
total_len : Int,
) -> Unit {
// Process digits in groups of 4 (chunks of 10000)
let (num, offset) = for num = num, offset = total_len - digit_start; num >=
10000U; {
let t = num / 10000U
let r = (num % 10000U).reinterpret_as_int()
let d1 = r / 100
let d2 = r % 100
let d1_hi = (0x30 + d1 / 10).to_uint16()
let d1_lo = (0x30 + d1 % 10).to_uint16()
let d2_hi = (0x30 + d2 / 10).to_uint16()
let d2_lo = (0x30 + d2 % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 4, d1_hi)
buffer.unsafe_set(digit_start + offset - 3, d1_lo)
buffer.unsafe_set(digit_start + offset - 2, d2_hi)
buffer.unsafe_set(digit_start + offset - 1, d2_lo)
continue t, offset - 4
} nobreak {
(num, offset)
}
// Handle remaining digits (< 10000)
// Process pairs of digits
let (remaining, offset) = for remaining = num.reinterpret_as_int(), offset = offset; remaining >=
100; {
let t = remaining / 100
let d = remaining % 100
let d_hi = (0x30 + d / 10).to_uint16()
let d_lo = (0x30 + d % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 2, d_hi)
buffer.unsafe_set(digit_start + offset - 1, d_lo)
continue t, offset - 2
} nobreak {
(remaining, offset)
}
// Handle final 1 or 2 digits
if remaining >= 10 {
let d_hi = (0x30 + remaining / 10).to_uint16()
let d_lo = (0x30 + remaining % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 2, d_hi)
buffer.unsafe_set(digit_start + offset - 1, d_lo)
} else {
buffer.unsafe_set(digit_start + offset - 1, (0x30 + remaining).to_uint16())
}
}
///|
/// Calculates the number of decimal digits in a u32 value
#cfg(not(target="js"))
fn dec_count32(value : UInt) -> Int {
// Binary search: split 1-10 digits into halves
if value >= 100000U { // >= 10^5 means 6+ digits
if value >= 10000000U { // >= 10^7 means 8+ digits
if value >= 1000000000U { // >= 10^9 means 10 digits
10
} else if value >= 100000000U { // >= 10^8 means 9 digits
9
} else {
8
}
} else if value >= 1000000U { // >= 10^6 means 7 digits
7
} else {
6
}
} else if value >= 1000U { // >= 10^3 means 4+ digits
if value >= 10000U { // >= 10^4 means 5 digits
5
} else {
4
}
} else if value >= 100U { // >= 10^2 means 3 digits
3
} else if value >= 10U { // >= 10^1 means 2 digits
2
} else {
1
}
}
///|
/// Calculates the number of hex digits needed for a u32 value
#cfg(not(target="js"))
fn hex_count32(value : UInt) -> Int {
if value == 0U {
1
} else {
let leading_zeros = value.clz()
(31 - leading_zeros) / 4 + 1
}
}
///|
/// Calculates the number of digits needed for a u32 value in any radix
#cfg(not(target="js"))
fn radix_count32(value : UInt, radix : Int) -> Int {
if value == 0U {
return 1
}
let base = radix.reinterpret_as_uint()
for num = value, count = 0; num > 0U; {
continue num / base, count + 1
} nobreak {
count
}
}
///|
/// Converts an integer to its string representation in the specified radix (base).
/// Example:
/// ```
/// inspect((255).to_string(radix=16), content="ff")
/// inspect((-255).to_string(radix=16), content="-ff")
/// ```
#cfg(not(target="js"))
pub fn Int::to_string(self : Int, radix? : Int = 10) -> String {
// Validate radix
if radix < 2 || radix > 36 {
abort("radix must be between 2 and 36")
}
// Special case for zero
if self == 0 {
return "0"
}
// Handle negative numbers
let is_negative = self < 0
let num : UInt = if is_negative {
// Negate and reinterpret as UInt
// Works correctly for Int::min_value due to two's complement:
// -Int::min_value wraps to itself, then reinterpreting gives 2147483648U
(-self).reinterpret_as_uint()
} else {
self.reinterpret_as_uint()
}
// Calculate length, allocate buffer, and write digits
let buffer = match radix {
10 => {
let digit_len = dec_count32(num)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int_to_string_dec(buffer, num, digit_start, total_len)
buffer
}
16 => {
let digit_len = hex_count32(num)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int_to_string_hex(buffer, num, digit_start, total_len)
buffer
}
_ => {
let digit_len = radix_count32(num, radix)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int_to_string_generic(buffer, num, digit_start, total_len, radix)
buffer
}
}
// Write minus sign if negative
if is_negative {
buffer.unsafe_set(0, 0x002D)
}
unsafe_fixedarray_uint16_to_string(buffer)
}
///|
/// Converts an unsigned integer to its string representation in the specified radix (base).
#cfg(not(target="js"))
pub fn UInt::to_string(self : UInt, radix? : Int = 10) -> String {
// Validate radix
if radix < 2 || radix > 36 {
abort("radix must be between 2 and 36")
}
// Special case for zero
if self == 0U {
return "0"
}
// Calculate length, allocate buffer, and write digits
let buffer = match radix {
10 => {
let len = dec_count32(self)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int_to_string_dec(buffer, self, 0, len)
buffer
}
16 => {
let len = hex_count32(self)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int_to_string_hex(buffer, self, 0, len)
buffer
}
_ => {
let len = radix_count32(self, radix)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int_to_string_generic(buffer, self, 0, len, radix)
buffer
}
}
unsafe_fixedarray_uint16_to_string(buffer)
}
//==========================================
// Int and UInt (JS)
//==========================================
///|
/// Converts an integer to its string representation in the specified radix (base).
#cfg(target="js")
pub fn Int::to_string(self : Int, radix? : Int = 10) -> String {
int_to_string_js(self, radix)
}
///|
#cfg(target="js")
extern "js" fn int_to_string_js(i : Int, radix : Int) -> String =
#|(x, radix) => {
#| return x.toString(radix);
#|}
///|
/// Converts an unsigned integer to its string representation in the specified radix (base).
#cfg(target="js")
pub fn UInt::to_string(self : UInt, radix? : Int = 10) -> String {
uint_to_string_js(self, radix)
}
///|
#cfg(target="js")
extern "js" fn uint_to_string_js(i : UInt, radix : Int) -> String =
#|(x, radix) => {
#| return (x >>> 0).toString(radix);
#|}
//==========================================
// Int64 and UInt64
//==========================================
///|
/// Calculates the number of decimal digits in a u64 value
#cfg(not(target="js"))
fn dec_count64(value : UInt64) -> Int {
// Binary search: split 1-20 digits into halves
if value >= 10000000000UL { // >= 10^10 means 11+ digits
if value >= 100000000000000UL { // >= 10^14 means 15+ digits
if value >= 10000000000000000UL { // >= 10^16 means 17+ digits
if value >= 1000000000000000000UL { // >= 10^18 means 19+ digits
if value >= 10000000000000000000UL { // >= 10^19 means 20 digits
20
} else {
19
}
} else if value >= 100000000000000000UL { // >= 10^17 means 18 digits
18
} else {
17
}
} else if value >= 1000000000000000UL { // >= 10^15 means 16 digits
16
} else {
15
}
} else if value >= 1000000000000UL { // >= 10^12 means 13+ digits
if value >= 10000000000000UL { // >= 10^13 means 14 digits
14
} else {
13
}
} else if value >= 100000000000UL { // >= 10^11 means 12 digits
12
} else {
11
}
} else if value >= 100000UL { // >= 10^5 means 6+ digits
if value >= 10000000UL { // >= 10^7 means 8+ digits
if value >= 1000000000UL { // >= 10^9 means 10 digits
10
} else if value >= 100000000UL { // >= 10^8 means 9 digits
9
} else {
8
}
} else if value >= 1000000UL { // >= 10^6 means 7 digits
7
} else {
6
}
} else if value >= 1000UL { // >= 10^3 means 4+ digits
if value >= 10000UL { // >= 10^4 means 5 digits
5
} else {
4
}
} else if value >= 100UL { // >= 10^2 means 3 digits
3
} else if value >= 10UL { // >= 10^1 means 2 digits
2
} else {
1
}
}
///|
/// Calculates the number of hex digits needed for a u64 value
#cfg(not(target="js"))
fn hex_count64(value : UInt64) -> Int {
if value == 0UL {
1
} else {
let leading_zeros = value.clz()
(63 - leading_zeros) / 4 + 1
}
}
///|
/// Calculates the number of digits needed for a u64 value in any radix
#cfg(not(target="js"))
fn radix_count64(value : UInt64, radix : Int) -> Int {
if value == 0UL {
return 1
}
let base = radix.to_uint64()
for num = value, count = 0; num > 0UL; {
continue num / base, count + 1
} nobreak {
count
}
}
///|
/// Converts an unsigned 64-bit integer to hexadecimal
#cfg(not(target="js"))
fn int64_to_string_hex(
buffer : FixedArray[UInt16],
num : UInt64,
digit_start : Int,
total_len : Int,
) -> Unit {
// Process 2 hex digits (1 byte) at a time
let (offset, n) = for offset = total_len - digit_start, n = num; offset >= 2; {
let byte_val = n.land(0xFFUL).to_int()
let hi = byte_val / 16
let lo = byte_val % 16
buffer.unsafe_set(digit_start + offset - 2, ALPHABET.unsafe_get(hi))
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(lo))
continue offset - 2, n >> 8
} nobreak {
(offset, n)
}
// Handle remaining single hex digit
if offset == 1 {
let nibble = n.land(0xFUL).to_int()
buffer.unsafe_set(digit_start, ALPHABET.unsafe_get(nibble))
}
}
///|
/// Generic radix conversion for any base 2-36 (64-bit)
#cfg(not(target="js"))
fn int64_to_string_generic(
buffer : FixedArray[UInt16],
num : UInt64,
digit_start : Int,
total_len : Int,
radix : Int,
) -> Unit {
let base = radix.to_uint64()
if (radix & (radix - 1)) == 0 {
// Power-of-two radix: use bit shifts
let shift = radix.ctz()
let mask = base - 1UL
for offset = total_len - digit_start, n = num; n > 0UL; {
let digit = n.land(mask).to_int()
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(digit))
continue offset - 1, n >> shift
}
} else {
// General radix: use division
for offset = total_len - digit_start, n = num; n > 0UL; {
let q = n / base
let digit = (n - q * base).to_int()
buffer.unsafe_set(digit_start + offset - 1, ALPHABET.unsafe_get(digit))
continue offset - 1, q
}
}
}
///|
/// Converts an unsigned 64-bit integer to decimal string
#cfg(not(target="js"))
fn int64_to_string_dec(
buffer : FixedArray[UInt16],
num : UInt64,
digit_start : Int,
total_len : Int,
) -> Unit {
// Process digits in groups of 4 (chunks of 10000)
let (num, offset) = for num = num, offset = total_len - digit_start; num >=
10000UL; {
let t = num / 10000UL
let r = (num % 10000UL).to_int()
let d1 = r / 100
let d2 = r % 100
let d1_hi = (0x30 + d1 / 10).to_uint16()
let d1_lo = (0x30 + d1 % 10).to_uint16()
let d2_hi = (0x30 + d2 / 10).to_uint16()
let d2_lo = (0x30 + d2 % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 4, d1_hi)
buffer.unsafe_set(digit_start + offset - 3, d1_lo)
buffer.unsafe_set(digit_start + offset - 2, d2_hi)
buffer.unsafe_set(digit_start + offset - 1, d2_lo)
continue t, offset - 4
} nobreak {
(num, offset)
}
// Handle remaining digits (< 10000)
// Process pairs of digits
let (remaining, offset) = for remaining = num.to_int(), offset = offset; remaining >=
100; {
let t = remaining / 100
let d = remaining % 100
let d_hi = (0x30 + d / 10).to_uint16()
let d_lo = (0x30 + d % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 2, d_hi)
buffer.unsafe_set(digit_start + offset - 1, d_lo)
continue t, offset - 2
} nobreak {
(remaining, offset)
}
// Handle final 1 or 2 digits
if remaining >= 10 {
let d_hi = (0x30 + remaining / 10).to_uint16()
let d_lo = (0x30 + remaining % 10).to_uint16()
buffer.unsafe_set(digit_start + offset - 2, d_hi)
buffer.unsafe_set(digit_start + offset - 1, d_lo)
} else {
buffer.unsafe_set(digit_start + offset - 1, (0x30 + remaining).to_uint16())
}
}
///|
/// Converts a 64-bit integer to its string representation in the specified radix (base).
#cfg(not(target="js"))
pub fn Int64::to_string(self : Int64, radix? : Int = 10) -> String {
// Validate radix
if radix < 2 || radix > 36 {
abort("radix must be between 2 and 36")
}
// Special case for zero
if self == 0L {
return "0"
}
// Handle negative numbers
let is_negative = self < 0L
let num : UInt64 = if is_negative {
// Negate and reinterpret as UInt64
// Works correctly for Int64::min_value due to two's complement
(-self).reinterpret_as_uint64()
} else {
self.reinterpret_as_uint64()
}
// Calculate length, allocate buffer, and write digits
let buffer = match radix {
10 => {
let digit_len = dec_count64(num)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int64_to_string_dec(buffer, num, digit_start, total_len)
buffer
}
16 => {
let digit_len = hex_count64(num)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int64_to_string_hex(buffer, num, digit_start, total_len)
buffer
}
_ => {
let digit_len = radix_count64(num, radix)
let total_len = digit_len + (if is_negative { 1 } else { 0 })
let buffer : FixedArray[UInt16] = FixedArray::make(total_len, 0)
let digit_start = if is_negative { 1 } else { 0 }
int64_to_string_generic(buffer, num, digit_start, total_len, radix)
buffer
}
}
// Write minus sign if negative
if is_negative {
buffer.unsafe_set(0, 0x002D)
}
unsafe_fixedarray_uint16_to_string(buffer)
}
///|
/// Converts an unsigned 64-bit integer to its string representation in the specified radix (base).
#cfg(not(target="js"))
pub fn UInt64::to_string(self : UInt64, radix? : Int = 10) -> String {
// Validate radix
if radix < 2 || radix > 36 {
abort("radix must be between 2 and 36")
}
// Special case for zero
if self == 0UL {
return "0"
}
// Calculate length, allocate buffer, and write digits
let buffer = match radix {
10 => {
let len = dec_count64(self)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int64_to_string_dec(buffer, self, 0, len)
buffer
}
16 => {
let len = hex_count64(self)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int64_to_string_hex(buffer, self, 0, len)
buffer
}
_ => {
let len = radix_count64(self, radix)
let buffer : FixedArray[UInt16] = FixedArray::make(len, 0)
int64_to_string_generic(buffer, self, 0, len, radix)
buffer
}
}
unsafe_fixedarray_uint16_to_string(buffer)
}
///|
/// Converts a 64-bit integer to its string representation in the specified radix (base).
#cfg(target="js")
pub fn Int64::to_string(self : Int64, radix? : Int = 10) -> String {
int64_to_string_js(self, radix)
}
///|
#cfg(target="js")
extern "js" fn int64_to_string_js(num : Int64, radix : Int) -> String =
#|(num, radix) => BigInt.asIntN(64, num).toString(radix)
///|
/// Converts an unsigned 64-bit integer to its string representation in the specified radix (base).
#cfg(target="js")
pub fn UInt64::to_string(self : UInt64, radix? : Int = 10) -> String {
uint64_to_string_js(self, radix)
}
///|
#cfg(target="js")
extern "js" fn uint64_to_string_js(num : UInt64, radix : Int) -> String =
#|(num, radix) => num.toString(radix)
//==========================================
// Int16 and UInt16
//==========================================
///|
/// Convert `UInt16` to string with optional radix.
///
/// Example:
///
/// ```mbt check
/// test {
/// inspect((255 : UInt16).to_string(), content="255")
/// inspect((255 : UInt16).to_string(radix=16), content="ff")
/// }
/// ```
pub fn UInt16::to_string(self : UInt16, radix? : Int = 10) -> String {
self.to_int().to_string(radix~)
}
//==========================================
// Test cases
//==========================================
///|
test "UInt::to_string" {
inspect(0U, content="0")
inspect(17U, content="17")
inspect(4294967295U, content="4294967295")
}
///|
test "to_string" {
assert_eq((0x100).to_string(), "256")
assert_eq("\{0x100}", "256")
assert_eq(0x200U.to_string(), "512")
assert_eq("\{0x200U}", "512")
assert_eq(0x300L.to_string(), "768")
assert_eq("\{0x300L}", "768")
assert_eq(0x400UL.to_string(), "1024")
assert_eq("\{0x400UL}", "1024")
}
///|
test "panic to_string_by_radix/illegal_radix" {
ignore((1).to_string(radix=1))
ignore((1).to_string(radix=37))
ignore(1L.to_string(radix=0))
ignore(1L.to_string(radix=42))
ignore(1U.to_string(radix=-1))
ignore(1U.to_string(radix=73))
ignore(1UL.to_string(radix=-100))
ignore(1UL.to_string(radix=100))
}