Bogue Tableau de quad (.q) Win - PB4.10 Beta 3

Archive.
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Bogue Tableau de quad (.q) Win - PB4.10 Beta 3

Message par Guimauve »

Bonjour,

Je ne peux pas dire si le bogue est apparent sur tout les OS (Window,
Linux ou MacOS) mais puisque le type quad est disponible pour les 3
platformes il y a de forte chance qu'il soit présent sur les 3.

Exemple :

Index = 2
Beta(Index) = 51
Beta(Index + 1) = 76
Beta(Index) + Beta(Index + 1) = 68719476863

Apparement le simple fait de faire Beta(Index + 1) ou Beta(Index - 1)
provoque le problème. Il semble que la valeur 51 (2e index du tableau)
soit ajouter à la valeur correspondant à l'adresse de la valeur 76
(3e index du tableau) et non à sa valeur.

Le problème est apparent pour les opérations d'addition, soustraction,
multiplication, division ou de comparaison.

- Beta(Index) + Beta(Index + 1)
- Beta(Index) - Beta(Index + 1)
- Beta(Index) * Beta(Index + 1)
- Beta(Index) / Beta(Index + 1)
- Beta(Index) < Beta(Index + 1)
- Beta(Index) > Beta(Index + 1)

En revanche si le calcul d'indexation est fait au préalable dans une
variable, le problème disparaît :

IndexB = Index + 1
Beta(Index) + Beta(IndexB)

A+
Guimauve

PS. : Ce bogue à déja été rapporté sur le forum anglais.

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Bogue Tableau de quad (.q)
; Fichier : Bogue Tableau de quad.pb
; Version : 1.0.0
; Programmé par : Guimauve
; Date : 02-02-2007
; Mise à jour : 02-02-2007
; Codé avec PureBasic V4.02
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Structure Alpha
   
   Tab.q[6]
   
EndStructure

Dim Beta.q(5)

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

For Index = 0 To 5
   
   Test.Alpha\Tab[Index] = Index * 5
   Beta(Index) = (Index * 25) + 1
   
Next

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Debug "Déboggue de la structure avec Step 2"
Debug ""

For Index = 0 To 5 Step 2

   Debug "Test\Tab[" + Str(Index) + "] = " + StrQ(Test\Tab[Index])
   Debug "Test\Tab[" + Str(Index + 1) + "] = " + StrQ(Test\Tab[Index+1])
   Debug "Test\Tab[" + Str(Index) + "] + Test\Tab[" + Str(Index + 1) + "] = " + StrQ(Test\Tab[Index] + Test\Tab[Index + 1])
   Debug Test\Tab[Index]
   Debug Test\Tab[Index + 1]
   Debug Test\Tab[Index] + Test\Tab[Index + 1]
   Debug ""
   
Next

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Debug "Déboggue du tableau avec Step 2"
Debug ""

For Index = 0 To 5 Step 2
   
   Debug "Beta(" + Str(Index) + ") = " + StrQ(Beta(Index))
   Debug "Beta(" + Str(Index + 1) + ") = " + StrQ(Beta(Index + 1))
   Debug "Beta(" + Str(Index) + ") + Beta(" + Str(Index + 1) + ") = " + StrQ(Beta(Index) + Beta(Index + 1))
   Debug Beta(Index)
   Debug Beta(Index + 1)
   Debug Beta(Index) + Beta(Index + 1)
   Debug ""
   
Next

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Debug "Déboggue du tableau avec Step -2"
Debug ""

For Index = 5 To 1 Step -2
   
   Debug "Beta(" + Str(Index) + ") = " + StrQ(Beta(Index))
   Debug "Beta(" + Str(Index - 1) + ") = " + StrQ(Beta(Index - 1))
   Debug "Beta(" + Str(Index) + ") + Beta(" + Str(Index - 1) + ") = " + StrQ(Beta(Index) + Beta(Index - 1))
   Debug Beta(Index)
   Debug Beta(Index - 1)
   Debug Beta(Index) + Beta(Index - 1)
   Debug ""
   
Next

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
Dernière modification par Guimauve le ven. 17/août/2007 2:57, modifié 3 fois.
linkerstorm
Messages : 20
Inscription : lun. 29/janv./2007 7:13

Message par linkerstorm »

Salut Guimauve.

Je me demande si c'est un problème avec les tableaux de QUAD ou un problème d'affichage par l'instruction Debug.

J'ai modifié légèrement ton code dans la première boucle :

Code : Tout sélectionner

...
   montest.q = Test\Tab[Index] + Test\Tab[Index + 1]
   Debug Test\Tab[Index] + Test\Tab[Index + 1]
   Debug montest
...
Le premier Debug affiche bien n'importe quoi mais le second affiche bien "5" qui est la bonne valeur.

J'en ai déduis que c'est l'instruction Debug qui déconne avec les Quad et pas les tableaux de Quad en eux-même.

Qu'en penses-tu ?

linkerstorm
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

Non, ce n'est pas un simple problème avec le debug. J'ai découvert ce boggue avec l'implémentation d'un algorythme de tri. Aucun problème avec les tableaux de long, une boucle infinie avec les tableaux de quad. Regarde le code suivant, il montre bien le problème.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Size Array Constants <<<<<

#BETA_LONGARRAY_MAX = 5
#BETA_QUADARRAY_MAX = 5

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

Structure Beta
   
   LongArray.l[#BETA_LONGARRAY_MAX]
   QuadArray.q[#BETA_QUADARRAY_MAX]
   
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The accessors <<<<<

Macro BetaLongArray(ObjetA, Index)
   
   ObjetA\LongArray[Index]
   
EndMacro

Macro BetaQuadArray(ObjetA, Index)
   
   ObjetA\QuadArray[Index]
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Debugging macro <<<<<

Macro DebugBetaQuadArray(ObjetA)
   
   For IndexQuad = 0 To #BETA_QUADARRAY_MAX - 1
      Debug BetaQuadArray(ObjetA, IndexQuad)
   Next
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< BubbleSort Ascendant operator <<<<<

Procedure BubbleSortAscendantBetaLongArray(*ObjetA.Beta)
   
   BubbleSortSwapped.b = #True
   
   While BubbleSortSwapped = #True
      
      BubbleSortSwapped = #False
      BubbleIndex = #BETA_LONGARRAY_MAX - 1
      StoneIndex = 0
      
      For Index = 0 To #BETA_LONGARRAY_MAX - 2
         
         If BetaLongArray(*ObjetA, StoneIndex) > BetaLongArray(*ObjetA, StoneIndex + 1)
            Swap BetaLongArray(*ObjetA, StoneIndex), BetaLongArray(*ObjetA, StoneIndex + 1)
            BubbleSortSwapped = #True
         EndIf
         
         If BetaLongArray(*ObjetA, BubbleIndex) < BetaLongArray(*ObjetA, BubbleIndex - 1)
            Swap BetaLongArray(*ObjetA, BubbleIndex), BetaLongArray(*ObjetA, BubbleIndex - 1)
            BubbleSortSwapped = #True
         EndIf
         
         BubbleIndex - 1
         StoneIndex + 1
         
      Next
      
   Wend
   
EndProcedure

Procedure BubbleSortAscendantBetaQuadArray(*ObjetA.Beta)
   
   BubbleSortSwapped.b = #True
   
   While BubbleSortSwapped = #True
      
      BubbleSortSwapped = #False
      BubbleIndex = #BETA_QUADARRAY_MAX - 1
      StoneIndex = 0
      
      For Index = 0 To #BETA_QUADARRAY_MAX - 2
         
         ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
         ; This part work with any type except with Quad. Why ???? See it work fine 
         ; with BubbleSortAscendantBetaLongArray(*ObjetA.Beta) procedure.

         If BetaQuadArray(*ObjetA, StoneIndex) > BetaQuadArray(*ObjetA, StoneIndex + 1)
            Swap BetaQuadArray(*ObjetA, StoneIndex), BetaQuadArray(*ObjetA, StoneIndex + 1)
            BubbleSortSwapped = #True
         EndIf
         
         ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
         ; Now if I precompute the Index + 1 outside the test. Everything work fine.
         ; It's very strange to me, don't you ? Also no problem with Index - 1.
         ; Why ???? It's the same logic
         
         ; StoneIndex2 = StoneIndex + 1
         ; 
         ; If BetaQuadArray(*ObjetA, StoneIndex) > BetaQuadArray(*ObjetA, StoneIndex2)
            ; Swap BetaQuadArray(*ObjetA, StoneIndex), BetaQuadArray(*ObjetA, StoneIndex + 1)
            ; BubbleSortSwapped = #True
         ; EndIf
         
         If BetaQuadArray(*ObjetA, BubbleIndex) < BetaQuadArray(*ObjetA, BubbleIndex - 1)
            Swap BetaQuadArray(*ObjetA, BubbleIndex), BetaQuadArray(*ObjetA, BubbleIndex - 1)
            BubbleSortSwapped = #True
         EndIf
         Debug ""
         DebugBetaQuadArray(*ObjetA)
         Debug ""
         BubbleIndex - 1
         StoneIndex + 1
         
      Next
      
   Wend
   
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Debugging macro <<<<<

Macro DebugBeta(ObjetA)
   
   Debug "LongArray"
   For Index = 0 To #BETA_LONGARRAY_MAX - 1
      Debug BetaLongArray(ObjetA, Index)
   Next
   
   Debug ""
   Debug "QuadArray"
   For Index = 0 To #BETA_QUADARRAY_MAX - 1
      Debug BetaQuadArray(ObjetA, Index)
   Next
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.016 seconds <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

BetaLongArray(Gamma.Beta, 0) = 5000000
BetaLongArray(Gamma.Beta, 1) = 25000
BetaLongArray(Gamma.Beta, 2) = 15000000
BetaLongArray(Gamma.Beta, 3) = 2500000
BetaLongArray(Gamma.Beta, 4) = 500000

BetaQuadArray(Gamma.Beta, 0) = 5000000
BetaQuadArray(Gamma.Beta, 1) = 25000
BetaQuadArray(Gamma.Beta, 2) = 15000000
BetaQuadArray(Gamma.Beta, 3) = 2500000
BetaQuadArray(Gamma.Beta, 4) = 500000


Debug "Original"
DebugBeta(Gamma)

BubbleSortAscendantBetaLongArray(Gamma)
BubbleSortAscendantBetaQuadArray(Gamma)

Debug ""
Debug "After BubbleSort"
DebugBeta(Gamma)

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
linkerstorm
Messages : 20
Inscription : lun. 29/janv./2007 7:13

Message par linkerstorm »

Oui, vu :?
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

"Bump"

Le problème est toujours présent dans la Version 4.10Beta.

Pour le tri avec tableau de type long, pas de problème, avec le type quad, boucle infinie. (J'ai modifié le code du message précédent en forçant la sortie après 3 X la grandeur du tableau)

Une consultation avec comparaison du genre "Index" avec "Index+1" ne fonctionne pas non plus. À Noter que seul les tableaux de type Quad sont affectés par ce problème.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; AUTOMATICALLY GENERATED CODE, DO NOT MODIFY
; UNLESS YOU REALLY, REALLY, REALLY MEAN IT !!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Size Array Constants <<<<<

#BETA_LONGARRAY_MAX = 5
#BETA_QUADARRAY_MAX = 5

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

Structure Beta
   
   LongArray.l[#BETA_LONGARRAY_MAX]
   QuadArray.q[#BETA_QUADARRAY_MAX]
   
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The accessors <<<<<

Macro BetaLongArray(ObjetA, Index)
   
   ObjetA\LongArray[Index]
   
EndMacro

Macro BetaQuadArray(ObjetA, Index)
   
   ObjetA\QuadArray[Index]
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Debugging macro <<<<<

Macro DebugBetaQuadArray(ObjetA)
   
   For IndexQuad = 0 To #BETA_QUADARRAY_MAX - 1
      Debug BetaQuadArray(ObjetA, IndexQuad)
   Next
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< BubbleSort Ascendant operator <<<<<

Procedure BubbleSortAscendantBetaLongArray(*ObjetA.Beta)
   
   BubbleSortSwapped.b = #True
   
   While BubbleSortSwapped = #True
      
      BubbleSortSwapped = #False
      BubbleIndex = #BETA_LONGARRAY_MAX - 1
      StoneIndex = 0
      
      For Index = 0 To #BETA_LONGARRAY_MAX - 2
         
         If BetaLongArray(*ObjetA, StoneIndex) > BetaLongArray(*ObjetA, StoneIndex + 1)
            Swap BetaLongArray(*ObjetA, StoneIndex), BetaLongArray(*ObjetA, StoneIndex + 1)
            BubbleSortSwapped = #True
         EndIf
         
         If BetaLongArray(*ObjetA, BubbleIndex) < BetaLongArray(*ObjetA, BubbleIndex - 1)
            Swap BetaLongArray(*ObjetA, BubbleIndex), BetaLongArray(*ObjetA, BubbleIndex - 1)
            BubbleSortSwapped = #True
         EndIf
         
         BubbleIndex - 1
         StoneIndex + 1
         
      Next
      
   Wend
   
EndProcedure

Procedure BubbleSortAscendantBetaQuadArray(*ObjetA.Beta)
   
   BubbleSortSwapped.b = #True
   
   While BubbleSortSwapped = #True
      
      BubbleSortSwapped = #False
      BubbleIndex = #BETA_QUADARRAY_MAX - 1
      StoneIndex = 0
      
      For Index = 0 To #BETA_QUADARRAY_MAX - 2
         
         If BetaQuadArray(*ObjetA, StoneIndex) > BetaQuadArray(*ObjetA, StoneIndex + 1)
            Swap BetaQuadArray(*ObjetA, StoneIndex), BetaQuadArray(*ObjetA, StoneIndex + 1)
            BubbleSortSwapped = #True
         EndIf
  
         If BetaQuadArray(*ObjetA, BubbleIndex) < BetaQuadArray(*ObjetA, BubbleIndex - 1)
            Swap BetaQuadArray(*ObjetA, BubbleIndex), BetaQuadArray(*ObjetA, BubbleIndex - 1)
            BubbleSortSwapped = #True
         EndIf
         
         Debug ""
         DebugBetaQuadArray(*ObjetA)
         Debug ""
         
         BubbleIndex - 1
         StoneIndex + 1
         
      Next
      
      Loop + 1
      
      If Loop >= 3 * #BETA_QUADARRAY_MAX
         Break
      EndIf    
      
   Wend
   
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Debugging macro <<<<<

Macro DebugBeta(ObjetA)
   
   Debug "LongArray"
   For Index = 0 To #BETA_LONGARRAY_MAX - 1
      Debug BetaLongArray(ObjetA, Index)
   Next
   
   Debug ""
   Debug "QuadArray"
   For Index = 0 To #BETA_QUADARRAY_MAX - 1
      Debug BetaQuadArray(ObjetA, Index)
   Next
   
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code generated in : 00.016 seconds <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

BetaLongArray(Gamma.Beta, 0) = 5000000
BetaLongArray(Gamma.Beta, 1) = 25000
BetaLongArray(Gamma.Beta, 2) = 15000000
BetaLongArray(Gamma.Beta, 3) = 2500000
BetaLongArray(Gamma.Beta, 4) = 500000

BetaQuadArray(Gamma.Beta, 0) = 5000000
BetaQuadArray(Gamma.Beta, 1) = 25000
BetaQuadArray(Gamma.Beta, 2) = 15000000
BetaQuadArray(Gamma.Beta, 3) = 2500000
BetaQuadArray(Gamma.Beta, 4) = 500000


Debug "Original"
DebugBeta(Gamma)

BubbleSortAscendantBetaLongArray(Gamma)
BubbleSortAscendantBetaQuadArray(Gamma)

Debug ""
Debug "After BubbleSort"
DebugBeta(Gamma)

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

Rappel, le bogue est toujours présent à la version 4.10 Beta 3.

A+
Guimauve
Répondre