Function AdditionAvecSigne$(x$, y$)
Dim negx As Boolean, negy As Boolean, neg As Boolean
Dim maxi%, t$, i%, z%, retenue As Byte
negx = Left(x, 1) = "-": negy = Left(y, 1) = "-"
x = Mid(x, 1 - negx): y = Mid(y, 1 - negy)
If negx And negy Then
AdditionAvecSigne = "-" & Additionner(x, y)
ElseIf Not negx And Not negy Then
AdditionAvecSigne = Additionner(x, y)
Else
maxi = Application.Max(Len(x), Len(y))
'---ajout de zéros à gauche pour avoir la même longueur---
x = String(maxi - Len(x), "0") & x
y = String(maxi - Len(y), "0") & y
neg = negx And x > y Or negy And y > x 'signe final
If x < y Then t = x: x = y: y = t 'classement
'---soustractions et résultat---
For i = maxi To 1 Step -1
z = Mid(x, i, 1) - Mid(y, i, 1) - retenue
If z < 0 Then z = z + 10: retenue = 1 Else retenue = 0
AdditionAvecSigne = z & AdditionAvecSigne
Next
'---suppression des zéros non significatifs---
For i = 1 To maxi - 1
If Mid(AdditionAvecSigne, i, 1) <> 0 Then Exit For
Next
AdditionAvecSigne = Mid(AdditionAvecSigne, i)
If neg Then AdditionAvecSigne = "-" & AdditionAvecSigne
End If
End Function