Multiply the big integer in place by a factor smaller than LIMB_BASE.
The widest product is (LIMB_BASE-1)*factor + carry, below 1.0e18,
which fits an int64 with room to spare. int64 is used deliberately:
the arithmetic must not narrow in a default int32 build.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout) | :: | limb(:) | |||
| integer(kind=default_int), | intent(inout) | :: | n_limb | |||
| integer(kind=int64), | intent(in) | :: | factor |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int64), | private | :: | carry | ||||
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=int64), | private | :: | product |
pure subroutine bd_mul_small(limb, n_limb, factor) !! Multiply the big integer in place by a factor smaller than `LIMB_BASE`. !! !! The widest product is `(LIMB_BASE-1)*factor + carry`, below 1.0e18, !! which fits an `int64` with room to spare. `int64` is used deliberately: !! the arithmetic must not narrow in a default int32 build. integer(int64), intent(inout) :: limb(:) integer(default_int), intent(inout) :: n_limb integer(int64), intent(in) :: factor integer(default_int) :: i integer(int64) :: carry, product carry = 0_int64 do i = 1_default_int, n_limb product = limb(i)*factor + carry limb(i) = mod(product, LIMB_BASE) carry = product/LIMB_BASE end do do while (carry > 0_int64) n_limb = n_limb + 1_default_int limb(n_limb) = mod(carry, LIMB_BASE) carry = carry/LIMB_BASE end do end subroutine bd_mul_small