1
- import { itoa , dtoa } from "./util/number" ;
1
+ import { itoa32 , utoa32 , itoa64 , utoa64 , dtoa } from "./util/number" ;
2
2
import { strtol } from "./util/string" ;
3
3
4
4
// @ts -ignore: decorator
@@ -32,9 +32,8 @@ export abstract class I8 {
32
32
return < i8 > strtol < i32 > ( value , radix ) ;
33
33
}
34
34
35
- toString ( this : i8 ) : String {
36
- // TODO: radix
37
- return itoa ( this ) ;
35
+ toString ( this : i8 , radix : i32 = 10 ) : String {
36
+ return itoa32 ( this , radix ) ;
38
37
}
39
38
}
40
39
@@ -53,9 +52,8 @@ export abstract class I16 {
53
52
return < i16 > strtol < i32 > ( value , radix ) ;
54
53
}
55
54
56
- toString ( this : i16 ) : String {
57
- // TODO: radix
58
- return itoa ( this ) ;
55
+ toString ( this : i16 , radix : i32 = 10 ) : String {
56
+ return itoa32 ( this , radix ) ;
59
57
}
60
58
}
61
59
@@ -74,9 +72,8 @@ export abstract class I32 {
74
72
return < i32 > strtol < i32 > ( value , radix ) ;
75
73
}
76
74
77
- toString ( this : i32 ) : String {
78
- // TODO: radix
79
- return itoa ( this ) ;
75
+ toString ( this : i32 , radix : i32 = 10 ) : String {
76
+ return itoa32 ( this , radix ) ;
80
77
}
81
78
}
82
79
@@ -95,9 +92,8 @@ export abstract class I64 {
95
92
return strtol < i64 > ( value , radix ) ;
96
93
}
97
94
98
- toString ( this : i64 ) : String {
99
- // TODO: radix
100
- return itoa ( this ) ;
95
+ toString ( this : i64 , radix : i32 = 10 ) : String {
96
+ return itoa64 ( this , radix ) ;
101
97
}
102
98
}
103
99
@@ -116,9 +112,12 @@ export abstract class Isize {
116
112
return < isize > strtol < i64 > ( value , radix ) ;
117
113
}
118
114
119
- toString ( this : isize ) : String {
120
- // TODO: radix
121
- return itoa ( this ) ;
115
+ toString ( this : isize , radix : i32 = 10 ) : String {
116
+ if ( sizeof < isize > ( ) == 4 ) {
117
+ return itoa32 ( this , radix ) ;
118
+ } else {
119
+ return itoa64 ( this , radix ) ;
120
+ }
122
121
}
123
122
}
124
123
@@ -137,9 +136,8 @@ export abstract class U8 {
137
136
return < u8 > strtol < i32 > ( value , radix ) ;
138
137
}
139
138
140
- toString ( this : u8 ) : String {
141
- // TODO: radix
142
- return itoa ( this ) ;
139
+ toString ( this : u8 , radix : i32 = 10 ) : String {
140
+ return utoa32 ( this , radix ) ;
143
141
}
144
142
}
145
143
@@ -158,9 +156,8 @@ export abstract class U16 {
158
156
return < u16 > strtol < i32 > ( value , radix ) ;
159
157
}
160
158
161
- toString ( this : u16 ) : String {
162
- // TODO: radix
163
- return itoa ( this ) ;
159
+ toString ( this : u16 , radix : i32 = 10 ) : String {
160
+ return utoa32 ( this , radix ) ;
164
161
}
165
162
}
166
163
@@ -179,9 +176,8 @@ export abstract class U32 {
179
176
return < u32 > strtol < i32 > ( value , radix ) ;
180
177
}
181
178
182
- toString ( this : u32 ) : String {
183
- // TODO: radix
184
- return itoa ( this ) ;
179
+ toString ( this : u32 , radix : i32 = 10 ) : String {
180
+ return utoa32 ( this , radix ) ;
185
181
}
186
182
}
187
183
@@ -200,9 +196,8 @@ export abstract class U64 {
200
196
return < u64 > strtol < i64 > ( value , radix ) ;
201
197
}
202
198
203
- toString ( this : u64 ) : String {
204
- // TODO: radix
205
- return itoa ( this ) ;
199
+ toString ( this : u64 , radix : i32 = 10 ) : String {
200
+ return utoa64 ( this , radix ) ;
206
201
}
207
202
}
208
203
@@ -221,9 +216,12 @@ export abstract class Usize {
221
216
return < usize > strtol < i64 > ( value , radix ) ;
222
217
}
223
218
224
- toString ( this : usize ) : String {
225
- // TODO: radix
226
- return itoa ( this ) ;
219
+ toString ( this : usize , radix : i32 = 10 ) : String {
220
+ if ( sizeof < isize > ( ) == 4 ) {
221
+ return utoa32 ( this , radix ) ;
222
+ } else {
223
+ return utoa64 ( this , radix ) ;
224
+ }
227
225
}
228
226
}
229
227
@@ -238,8 +236,7 @@ export abstract class Bool {
238
236
@lazy
239
237
static readonly MAX_VALUE : bool = bool . MAX_VALUE ;
240
238
241
- toString ( this : bool ) : String {
242
- // TODO: radix?
239
+ toString ( this : bool , radix : i32 = 0 ) : String {
243
240
return this ? "true" : "false" ;
244
241
}
245
242
}
@@ -305,8 +302,7 @@ export abstract class F32 {
305
302
return < f32 > parseFloat ( value ) ;
306
303
}
307
304
308
- toString ( this : f32 ) : String {
309
- // TODO: radix
305
+ toString ( this : f32 , radix : i32 = 0 ) : String {
310
306
return dtoa ( this ) ;
311
307
}
312
308
}
@@ -371,7 +367,6 @@ export abstract class F64 {
371
367
}
372
368
373
369
toString ( this : f64 , radix : i32 = 0 ) : String {
374
- // TODO: radix
375
370
return dtoa ( this ) ;
376
371
}
377
372
}
0 commit comments