@@ -322,13 +322,14 @@ func Div32(hi, lo, y uint32) (quo, rem uint32) {
322322
323323//gopherjs:replace
324324func Div64 (hi , lo , y uint64 ) (quo , rem uint64 ) {
325- // Reference: "The Art of Computer Programming" (TAoCP) Vol. 2 by Knuth
326- // (a copy can be found at https://github.com/Code42Cate/The-Art-of-Computer-Programming/blob/master/Volume2.pdf)
327- // describes Algorithm D (Division of nonnegative integers) in 4.3.1 starting on page 257.
328- //
329325 // This code is similar to the original math/bits.Div64 with all arithmetic
330326 // operating on 32-bit halves to avoid using uint64 operations that we have
331327 // to emulate in JS.
328+ //
329+ // The original math/bits.Div64 appears to be based on:
330+ // "The Art of Computer Programming" (TAoCP) Vol. 2 by Knuth
331+ // (a copy can be found at https://github.com/Code42Cate/The-Art-of-Computer-Programming/blob/master/Volume2.pdf)
332+ // describes Algorithm D (Division of nonnegative integers) in 4.3.1 starting on page 257.
332333 yHi := js .Uint64High (y )
333334 yLo := js .Uint64Low (y )
334335 if yHi == 0 && yLo == 0 {
@@ -342,7 +343,7 @@ func Div64(hi, lo, y uint64) (quo, rem uint64) {
342343 loHi := js .Uint64High (lo )
343344 loLo := js .Uint64Low (lo )
344345
345- // Fast path: divisor fits in 32 bits. The y > hi precondition forces
346+ // If divisor fits in 32 bits, then the y > hi precondition forces
346347 // hiHi == 0 and hiLo < yLo, so neither Div32 below can overflow.
347348 if yHi == 0 {
348349 q1 , r1 := Div32 (hiLo , loHi , yLo )
@@ -351,7 +352,7 @@ func Div64(hi, lo, y uint64) (quo, rem uint64) {
351352 js .MakeUint64 (0 , float64 (r0 ))
352353 }
353354
354- // General case: yHi != 0 (full 64-bit divisor).
355+ // yHi != 0 (full 64-bit divisor).
355356 // Normalize so the divisor's top bit is set; s is in [0, 31].
356357 s := uint (LeadingZeros32 (yHi ))
357358 rs := 32 - s
0 commit comments