Skip to content

Commit 20a1af3

Browse files
authored
math.unsigned: add missing docstrings for the functions in unint128.v (#19597)
1 parent 79b068b commit 20a1af3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

vlib/math/complex/complex.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub mut:
1212
im f64
1313
}
1414

15-
// complex returns a complex struct with the given `re` and `im`
15+
// complex returns a complex struct with the given `re`al and `im`aginary parts
1616
pub fn complex(re f64, im f64) Complex {
1717
return Complex{re, im}
1818
}

vlib/math/unsigned/uint128.v

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn (u Uint128) and(v Uint128) Uint128 {
6969
return Uint128{u.lo & v.lo, u.hi & v.hi}
7070
}
7171

72-
// and_64 rreturns u & v
72+
// and_64 returns u & v
7373
pub fn (u Uint128) and_64(v u64) Uint128 {
7474
return Uint128{u.lo & v, u.hi & 0}
7575
}
@@ -101,6 +101,7 @@ pub fn (u Uint128) add(v Uint128) Uint128 {
101101
return Uint128{lo, hi}
102102
}
103103

104+
// add_128 return u + v and the carry
104105
pub fn add_128(x Uint128, y Uint128, carry u64) (Uint128, u64) {
105106
mut sum := Uint128{}
106107
mut carry_out := u64(0)
@@ -109,6 +110,7 @@ pub fn add_128(x Uint128, y Uint128, carry u64) (Uint128, u64) {
109110
return sum, carry_out
110111
}
111112

113+
// sub_128 returns u - v and the borrow
112114
pub fn sub_128(x Uint128, y Uint128, borrow u64) (Uint128, u64) {
113115
mut diff := Uint128{}
114116
mut borrow_out := u64(0)
@@ -117,6 +119,7 @@ pub fn sub_128(x Uint128, y Uint128, borrow u64) (Uint128, u64) {
117119
return diff, borrow_out
118120
}
119121

122+
// mul_128 returns u x v
120123
pub fn mul_128(x Uint128, y Uint128) (Uint128, Uint128) {
121124
mut lo := Uint128{}
122125
mut hi := Uint128{}
@@ -135,6 +138,7 @@ pub fn mul_128(x Uint128, y Uint128) (Uint128, Uint128) {
135138
return hi, lo
136139
}
137140

141+
// div_128 returns u / v
138142
pub fn div_128(hi Uint128, lo Uint128, y_ Uint128) (Uint128, Uint128) {
139143
mut y := y_
140144
if y.is_zero() {
@@ -211,6 +215,7 @@ pub fn (u Uint128) mul_64(v u64) Uint128 {
211215
return Uint128{lo, hi}
212216
}
213217

218+
// overflowing_mul_64 returns u x v even if result size > 64
214219
pub fn (u Uint128) overflowing_mul_64(v u64) (Uint128, bool) {
215220
hi, lo := bits.mul_64(u.lo, v)
216221
p0, p1 := bits.mul_64(u.hi, v)
@@ -219,6 +224,7 @@ pub fn (u Uint128) overflowing_mul_64(v u64) (Uint128, bool) {
219224
return Uint128{lo, hi2}, p0 != 0 || c0 != 0
220225
}
221226

227+
// overflowing_add_64 returns u = v even if result size > 64
222228
pub fn (u Uint128) overflowing_add_64(v u64) (Uint128, u64) {
223229
lo, carry := bits.add_64(u.lo, v, 0)
224230
hi, carry2 := bits.add_64(u.hi, 0, carry)
@@ -366,6 +372,7 @@ pub fn (u Uint128) reverse_bytes() Uint128 {
366372
return Uint128{bits.reverse_bytes_64(u.hi), bits.reverse_bytes_64(u.lo)}
367373
}
368374

375+
// not
369376
pub fn (u Uint128) not() Uint128 {
370377
return Uint128{~u.lo, ~u.hi}
371378
}
@@ -413,10 +420,12 @@ pub fn uint128_from_64(v u64) Uint128 {
413420
return uint128_new(v, 0)
414421
}
415422

423+
// uint128_new creates new Uint128 with given `lo` and `hi`
416424
pub fn uint128_new(lo u64, hi u64) Uint128 {
417425
return Uint128{lo, hi}
418426
}
419427

428+
// unint_from_dec_str returns an error or new Uint128 from given string
420429
pub fn uint128_from_dec_str(value string) !Uint128 {
421430
mut res := unsigned.uint128_zero
422431
for b_ in value.bytes() {
@@ -441,26 +450,32 @@ pub fn uint128_from_dec_str(value string) !Uint128 {
441450
return res
442451
}
443452

453+
// / -> returns u / v
444454
pub fn (u Uint128) / (v Uint128) Uint128 {
445455
return u.div(v)
446456
}
447457

458+
// % -> returns u % v
448459
pub fn (u Uint128) % (v Uint128) Uint128 {
449460
return u.mod(v)
450461
}
451462

463+
// + -> returns u + v
452464
pub fn (u Uint128) + (v Uint128) Uint128 {
453465
return u.add(v)
454466
}
455467

468+
// - -> returns u - v
456469
pub fn (u Uint128) - (v Uint128) Uint128 {
457470
return u.sub(v)
458471
}
459472

473+
// * -> returns u * v
460474
pub fn (u Uint128) * (v Uint128) Uint128 {
461475
return u.mul(v)
462476
}
463477

478+
// < -> returns true if u < v
464479
pub fn (u Uint128) < (v Uint128) bool {
465480
return u.cmp(v) == -1
466481
}

0 commit comments

Comments
 (0)