Traduction C++ To Vb

cs_jmtoulon Messages postés 85 Date d'inscription dimanche 1 avril 2001 Statut Membre Dernière intervention 3 août 2010 - 20 févr. 2006 à 07:18
cs_jmtoulon Messages postés 85 Date d'inscription dimanche 1 avril 2001 Statut Membre Dernière intervention 3 août 2010 - 20 févr. 2006 à 12:14
Bonjour, je cherche à créer une fonction Math en VB
J'ai trouvé l'equivalent en c++ seulement il faudrais que quelqu'un de tres gentil me le traduise en VB svp ::)


<OL>
<LI>
int
jacobi(
int
m,
int
n){
<LI>
<LI>
int
t;
<LI>
<LI>
if
(m>n) m=m%n;
<LI>
if
(m==0)
return
0;
<LI>
if
(m==1)
return
1;
<LI>
if
(m==2) {
<LI>
if
(n&1==0)
return
0;
<LI> t=n&7; <SAMP>/* t = n % 8 */</SAMP>
<LI>
if
(t==1 || t==7)
return
1;
<LI>
return
-1;
<LI> }
<LI>
if
((m&1)==0)
<LI>
return
jacobi((m>>1),n)*jacobi(2,n);
<LI>
if
((m&3)==3 && (n&3)==3)
return
-jacobi(n,m);
<LI>
return
jacobi(n,m);
<LI>
<LI>} </LI></OL>
Merci :)

3 réponses

econs Messages postés 4030 Date d'inscription mardi 13 mai 2003 Statut Membre Dernière intervention 23 décembre 2008 24
20 févr. 2006 à 09:03
Salut,



Ca doit donner quelquechose comme ceci (pas testé) :





Public Function Jacobi(m As Integer, n As Integer) As Integer

Dim t As Integer



If m>n Then m = m Mod n

If m=0 Then Jacobi=0

If m=1 Then Jacobi=1

If m=2 Then

If (n And 1)=0 Then Jacobi=0

t=n And 7

If (t=1 Or t=7) Then Jacobi=1

Jacobi=-1

End If

If (m And 1)=0 Then Jacobi=Jacobi(Int(m/2),n)*Jacobi(2,n)

If (m And 3)=3 And (n And 3)=3 Then Jacobi=Jacobi(n,m)*-1

Jacobi = Jacobi(n,m)

End Sub


Manu
0
Egyde Messages postés 158 Date d'inscription lundi 17 mai 2004 Statut Membre Dernière intervention 16 juillet 2007
20 févr. 2006 à 09:52
C'est pas tout à fait ça econs (int en C++ devient Long en VB. De plus, quand on return, on quitte la fonction, ie ton programme relance Jacobi si "m And 1" et "m=0"

Public Function jacobi(ByVal m As Long, ByVal n As Long)

Dim t As Long

If (m > n) Then
m = m Mod n
End If
If (m 0) Then jacobi 0: Exit Function
If (m 1) Then jacobi 1: Exit Function
If (m = 2) Then
If (n And 1)=0 Then jacobi = 0: Exit Function
t n And 7; ' t n % 8
If (t 1) Or (t 7) Then
jacobi = 1
Else
jacobi = -1
End If
Exit Function
End If

If ((m And 1) = 0) Then
jacobi = jacobi(m\2,n)*jacobi(2,n)
ElseIf (m And 3)=3 And (n And 3)=3 Then
jacobi = -jacobi(n,m)
Else
jacobi = jacobi(n,m)
End If

End Function
0
cs_jmtoulon Messages postés 85 Date d'inscription dimanche 1 avril 2001 Statut Membre Dernière intervention 3 août 2010
20 févr. 2006 à 12:14
Lol merci pour vos réponses ;)

Je viens de me rendre compte que la fonction jacobi n'est pas adapté à mon projet, je post donc un new msg dans le forum ;)

merci encore
0
Rejoignez-nous