1)這是作者的一段話
strOutPut = str1 * str2 using character algorithm, slow but honest. Whole numbers only Inner
loop is optimized and hard to understand, but it works.
2)程式碼如下,本人一直猜不透作者背後的數學依據為何,請各位數學
底子好的高手,幫忙解釋此段。
 For intIndex = 0 To intLast - 1
    lngK = intLast1 - intIndex
    
    sj = 1 - lngK
    
    If sj < 0 Then
      sj = 0
    End If
    
    ej = intLast1 - lngK
    
    If ej > intLast2 - 1 Then
      ej = intLast2 - 1
    End If
3)Private Sub dhMulChar(ByVal str1 As String, ByVal str2 As String, ByRef strOutput As String)
  Dim intLast1          As Integer
  Dim intLast2          As Integer
  Dim intLast           As Integer
  Dim intIndex          As Integer
  
  Dim sj             As Integer
  Dim ej             As Integer
  Dim lngJ            As Long
  Dim lngK            As Long
  Dim lngProduct         As Long
  
  ' 計算第一字串長度。
  intLast1 = Len(str1)
  
  ' 計算第二字串長度。
  intLast2 = Len(str2)
  
  ' 計算小數點位置。
  ' 如12.34 * 56.78
  ' 小算點位數為相加 2 + 2 = 4位。
  intLast = intLast1 + intLast2
  
  ' 給與空白位置。
  strOutput = Space(intLast)
  
  ' 給與乘積變數為零。
  lngProduct = 0

' 是從個位數開始計算。
  For intIndex = 0 To intLast - 1
    lngK = intLast1 - intIndex
    
    sj = 1 - lngK
    
    If sj < 0 Then
      sj = 0
    End If
    
    ej = intLast1 - lngK
    
    If ej > intLast2 - 1 Then
      ej = intLast2 - 1
    End If
    
    For lngJ = sj To ej
      lngProduct = lngProduct + Val(Mid(str1, lngK + lngJ, 1)) * Val(Mid(str2, intLast2 - lngJ, 1))
    Next
    
    Mid(strOutput, intLast - intIndex, 1) = Chr(mintAsc0 + CInt(lngProduct Mod 10))
    
    lngProduct = lngProduct \ 10
  Next intIndex
  
  If lngProduct Then
    strOutput = LTrim(Str(lngProduct)) & strOutput
  End If

End Sub
arrow
arrow
    全站熱搜

    vbqa 發表在 痞客邦 留言(6) 人氣()