On ne connait pas la déclaration de ta fonction
Public Function Karatsuba(ByVal N1 As String, ByVal N2 As String)
On ne sait pas ce que tu en attends et à quoi elle sert
Si N1 et N2 sont des entiers, Len(N1) n'a aucun sens.
Pas plus de sens à StrComp(L1, L2) où L1/L2 sont des Long
X1 = Mid(N1, 1, M) ?? alors que X1 est un objet ?
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Function Karatsuba(ByVal N1 As String, ByVal N2 As String) 'variables Dim N1_long, N2_long Dim Res As Long Dim Lbig, M As Long Dim X1_str, X2_str, Y1_str, Y2_str, X3_str, Y3_str As String Dim X1_long, X2_long, Y1_long, Y2_long, X3_long, Y3_long As Long Dim A_str, B_str, C_str As String Dim A_long, B_long, C_long As Long Dim D_long, E_long As Long Dim MaxLon As Integer ' Etape 1: determiner la longeur de N1 et N2 afin de savoir si _ ' on utilise la methode normale de multiplication(petits nombres) _ ' ou celle de KARATSUBA(grands nombres) MaxLon = 5 ' limite de la methode normale If Len(N1) < Len(N2) Then Lbig = Len(N2) Else : Lbig = Len(N1) End If If Lbig < MaxLon Then ' si on doit utliser la methode normale N1_long = CLng(N1) N2_long = CLng(N2) Res = N1_long * N2_long Karatsuba = CStr(Res) ' resultat de la multiplication Exit Function Else ' sinon methode de Karatsuba M = Lbig / 2 ' diviser pou regner X1_str = Mid(N1, 1, M) ' on divise N1 en 2 blocs X2_str = Mid(N1, M + 1, M) Y1_str = Mid(N2, 1, M) ' on divise N2 en 2 blocs Y2_str = Mid(N2, M + 1, M) X1_long = CLng(X1_str) X2_long = CLng(X2_str) Y1_long = CLng(Y1_str) Y2_long = CLng(Y2_str) X3_long = X1_long + X2_long X3_str = CStr(X3_long) Y3_long = Y1_long + Y2_long Y3_str = CStr(Y3_long) A_str = Karatsuba(X2_str, Y2_str) 'calcul de X2,Y2 A_long = CLng(A_str) B_str = Karatsuba(X1_str, Y1_str) 'calcul de X1,Y1 B_long = CLng(B_str) C_str = Karatsuba(X3_str, Y3_str) 'calcul de ...soit C C_long = CLng(C_str) D_long = (C_long - A_long - B_long) * 10 ^ M E_long = B_long * 10 ^ (2 * M) Res = A_long + D_long + E_long Karatsuba = CStr(Res) ' resultat de la multiplication End If End Function
Dim N1 As Integer = 456789123 Dim N2 As Integer = 123456789 Dim maVar As Long = CLng(N1) * CLng(N2) MsgBox(maVar)