Skip to content

Commit c9e50f0

Browse files
authored
builtin: document the rest of int.v and fix some typos in the docs (#27873)
1 parent ba11067 commit c9e50f0

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

vlib/builtin/int.v

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ pub fn (n u16) str() string {
140140
return int(n).str_l(6)
141141
}
142142

143+
// str returns the value of the `i32` as a `string`.
144+
// Example: assert i32(-32769).str() == '-32769'
143145
pub fn (n i32) str() string {
144146
return int(n).str_l(11)
145147
}
146148

149+
// hex_full returns the value of the `int` as a *full* 8-digit hexadecimal `string`.
150+
// Example: assert int(20).hex_full() == '00000014'
151+
// Example: assert int(-20).hex_full() == 'ffffffec'
147152
pub fn (nn int) hex_full() string {
148153
return u64_to_hex(u64(nn), 8)
149154
}
@@ -441,55 +446,74 @@ pub fn (nn i64) hex() string {
441446

442447
// hex returns the value of the `int_literal` as a hexadecimal `string`.
443448
// Note that the output is ***not*** zero padded.
449+
// Example: assert 255.hex() == 'ff'
444450
pub fn (nn int_literal) hex() string {
445451
return u64(nn).hex()
446452
}
447453

448-
// hex returns the value of the `voidptr` as a hexadecimal `string`.
449-
// Note that the output is ***not*** zero padded.
454+
// str returns the value of the `voidptr` as a '0x'-prefixed hexadecimal `string`.
455+
// Note that the output after '0x' is ***not*** zero padded.
450456
pub fn (nn voidptr) str() string {
451457
return '0x' + u64(nn).hex()
452458
}
453459

454-
// hex returns the value of the `byteptr` as a hexadecimal `string`.
455-
// Note that the output is ***not*** zero padded.
456-
// pub fn (nn byteptr) str() string {
460+
// str returns the value of the `byteptr` as a '0x'-prefixed hexadecimal `string`.
461+
// Note that the output after '0x' is ***not*** zero padded.
457462
pub fn (nn byteptr) str() string {
458463
return '0x' + u64(nn).hex()
459464
}
460465

466+
// str returns the value of the `charptr` as a '0x'-prefixed hexadecimal `string`.
467+
// Note that the output after '0x' is ***not*** zero padded.
461468
pub fn (nn charptr) str() string {
462469
return '0x' + u64(nn).hex()
463470
}
464471

472+
// hex_full returns the value of the `u8` as a *full* 2-digit hexadecimal `string`.
473+
// Example: assert u8(5).hex_full() == '05'
465474
pub fn (nn u8) hex_full() string {
466475
return u64_to_hex(u64(nn), 2)
467476
}
468477

478+
// hex_full returns the value of the `i8` as a *full* 2-digit hexadecimal `string`.
479+
// Example: assert i8(-5).hex_full() == 'fb'
469480
pub fn (nn i8) hex_full() string {
470481
return u64_to_hex(u64(nn), 2)
471482
}
472483

484+
// hex_full returns the value of the `u16` as a *full* 4-digit hexadecimal `string`.
485+
// Example: assert u16(5).hex_full() == '0005'
473486
pub fn (nn u16) hex_full() string {
474487
return u64_to_hex(u64(nn), 4)
475488
}
476489

490+
// hex_full returns the value of the `i16` as a *full* 4-digit hexadecimal `string`.
491+
// Example: assert i16(-5).hex_full() == 'fffb'
477492
pub fn (nn i16) hex_full() string {
478493
return u64_to_hex(u64(nn), 4)
479494
}
480495

496+
// hex_full returns the value of the `u32` as a *full* 8-digit hexadecimal `string`.
497+
// Example: assert u32(5).hex_full() == '00000005'
481498
pub fn (nn u32) hex_full() string {
482499
return u64_to_hex(u64(nn), 8)
483500
}
484501

502+
// hex_full returns the value of the `i64` as a *full* 16-digit hexadecimal `string`.
503+
// Example: assert i64(-5).hex_full() == 'fffffffffffffffb'
485504
pub fn (nn i64) hex_full() string {
486505
return u64_to_hex(u64(nn), 16)
487506
}
488507

508+
// hex_full returns the value of the `voidptr` as a *full* 16-digit hexadecimal `string`.
509+
// Note that the output has ***no*** '0x' prefix, unlike `voidptr.str()`.
510+
// Example: assert voidptr(255).hex_full() == '00000000000000ff'
489511
pub fn (nn voidptr) hex_full() string {
490512
return u64_to_hex(u64(nn), 16)
491513
}
492514

515+
// hex_full returns the value of the `int_literal` as a *full* 16-digit hexadecimal `string`.
516+
// Example: assert 255.hex_full() == '00000000000000ff'
493517
pub fn (nn int_literal) hex_full() string {
494518
return u64_to_hex(u64(nn), 16)
495519
}

0 commit comments

Comments
 (0)