1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
Sub Test()
Debug.Print result_puissance(35, 34)
End Sub
Function result_puissance(N As Long, K As Long) As String
'FORMULE PATRICKTOULON DVP
Dim Nb1 As String, Nb2 As String, i#
Nb1 = CStr(N)
For i = 1 To K - 1
Nb2 = CStr(N - i)
Nb1 = PGN(Nb1, Nb2)
Next
result_puissance = Nb1
End Function
Function PGN(ByVal Nb1 As String, ByVal Nb2 As String) As String
'PRODUIT GRANDS NOMBRES
'Info sur les longueurs des termes
Dim L1 As Long, L2 As Long
L1 = Len(Nb1): L2 = Len(Nb2)
'Recherche des signes et conversion en nombre positif
Dim S1 As Long, S2 As Long
S1 = 1: S2 = 1
If Left$(Nb1, 1) = "-" Then S1 = -1: Nb1 = Right$(Nb1, L1 - 1): L1 = L1 - 1
If Left$(Nb2, 1) = "-" Then S2 = -1: Nb2 = Right$(Nb2, L2 - 1): L2 = L2 - 1
'Recherche de la décimale et conversion en entier
Dim P1 As Long, P2 As Long, Virgule As Long
'Recherche emplacement de la virgule
P1 = InStr(1, Nb1, ",") + InStr(1, Nb1, ".")
P2 = InStr(1, Nb2, ",") + InStr(1, Nb2, ".")
'Recompose en entier
If P1 > 0 Then
Nb1 = Left$(Nb1, P1 - 1) & Right$(Nb1, L1 - P1)
Virgule = L1 - P1
L1 = L1 - 1
End If
If P2 > 0 Then
Nb2 = Left$(Nb2, P2 - 1) & Right$(Nb2, L2 - P2)
Virgule = Virgule + L2 - P2
L2 = L2 - 1
End If
'Découpage en tranche
Dim K1 As Long, K2 As Long, Kt As Long
K1 = L1 \ 7 + 1: K2 = L2 \ 7 + 1: Kt = K1 + K2
'Tableaux de stockage des tranches
ReDim A(K1) As Double, B(K2) As Double
'Remplissage tableau
Dim i As Long, j As Long
For i = 0 To K1 - 2
A(i) = Mid$(Nb1, L1 - 6 - i * 7, 7)
Next i
A(K1 - 1) = 0
If L1 Mod 7 <> 0 Then A(K1 - 1) = Left$(Nb1, L1 Mod 7)
For i = 0 To K2 - 2
B(i) = Mid$(Nb2, L2 - 6 - i * 7, 7)
Next i
B(K2 - 1) = 0
If L2 Mod 7 <> 0 Then B(K2 - 1) = Left$(Nb2, L2 Mod 7)
'Base de calcul
Dim Base As Long
Base = 10 ^ 7
'Déclaration des indices
ReDim t(Kt + 1) As Double
'Algo multiplication
Dim P As Double, Q As Double, K As Long, Saut As Long, L As Double
Saut = 90
For j = 0 To K1
L = A(j)
If j = Saut Then Saut = Saut + 90: GoSub Recalcul
For i = 0 To K2
t(i + j) = L * B(i) + t(i + j)
Next i
Next j
GoSub Recalcul
GoTo suite:
Recalcul: 'recalculs des indices t() dans la Base avant dépassement de capacité
P = 0
For K = 0 To K2 + j
Q = Int((t(K) + P) / Base)
t(K) = t(K) + P - Q * Base
P = Q
Next K
Return
suite:
'Rajoute les zeros dans les indices moins long que 7 chiffres
Dim Z As String 'optimisation string$
Z = "0"
Dim ln10 As Double
ln10 = Log(10)
For i = Kt To 0 Step -1
PGN = PGN & String$(6 - Fix(Log(t(i) + 0.11) / ln10), Z) & t(i)
Next i
'Supprime les zeros inutiles
PGN = ZeroGN(PGN)
'Replacement de la virgule
Dim PS As Long
If Virgule <> 0 Then
PS = Len(PGN) - Virgule
If PS < 0 Then PGN = String$(-PS, Z) & PGN
PGN = Left$(PGN, Len(PGN) - Virgule) & "," & Right$(PGN, Virgule)
End If
'Mise en forme
PGN = ZeroGN(PGN)
'Règle des signes
If S1 * S2 = -1 And PGN <> "0" Then PGN = "-" & PGN
End Function
Function ZeroGN(ByVal Term1 As String) As String
'RETIRE LES ZEROS INUTILES
'Boucle de recherche des zéros inutiles dans la partie entière
Dim i As Long
For i = 1 To Len(Term1)
If Mid$(Term1, i, 1) <> "0" Then Exit For
Next i
Term1 = Mid$(Term1, i)
If Term1 = vbNullString Then Term1 = "0" 'traite le cas d'un nombre nul
'Recherche si virgule
Dim V As Long
V = InStr(1, Term1, ",") + InStr(1, Term1, ".")
'Recherche si Term1<1, si oui remet un zéro devant la virgule
If V = 1 Then Term1 = "0" & Term1: V = 2
'Boucle de recherche des zéros inutiles dans partie décimale
If V > 0 Then
For i = Len(Term1) To V - 1 Step -1
If Mid$(Term1, i, 1) <> "0" Then Exit For
Next i
Term1 = Left$(Term1, i)
End If
'Recherche si dernier=virgule, si oui=supprime
If V = Len(Term1) Then Term1 = Left$(Term1, V - 1)
'Renvoi
ZeroGN = Term1
End Function |
Partager