bd_mul_small Subroutine

private 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.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout) :: limb(:)
integer(kind=default_int), intent(inout) :: n_limb
integer(kind=int64), intent(in) :: factor

Called by

proc~~bd_mul_small~~CalledByGraph proc~bd_mul_small bd_mul_small proc~bd_mul_pow bd_mul_pow proc~bd_mul_pow->proc~bd_mul_small proc~expand_exact expand_exact proc~expand_exact->proc~bd_mul_pow proc~to_string_fixed_dp to_string_fixed_dp proc~to_string_fixed_dp->proc~expand_exact proc~to_string_sci_dp to_string_sci_dp proc~to_string_sci_dp->proc~expand_exact interface~to_string_fixed to_string_fixed interface~to_string_fixed->proc~to_string_fixed_dp proc~to_string_fixed_sp to_string_fixed_sp interface~to_string_fixed->proc~to_string_fixed_sp interface~to_string_sci to_string_sci interface~to_string_sci->proc~to_string_sci_dp proc~to_string_sci_sp to_string_sci_sp interface~to_string_sci->proc~to_string_sci_sp proc~to_string_fixed_sp->proc~to_string_fixed_dp proc~to_string_sci_sp->proc~to_string_sci_dp

Variables

Type Visibility Attributes Name Initial
integer(kind=int64), private :: carry
integer(kind=default_int), private :: i
integer(kind=int64), private :: product

Source Code

   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