It is currently Wed Jan 27, 2021 5:18 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Bug or programming error?
PostPosted: Wed Oct 14, 2015 10:58 pm 
Offline
User
User

Joined: Mon Aug 17, 2009 10:48 pm
Posts: 49
Location: France
Bug or programming error ?
Here are 2 prg that work properly

Code:
Macro _q_t_
  "

EndMacro
Macro _n (__n)
  _q_t_#__n#=_q_t_+Str(__n)+" "
EndMacro
Macro _d (__D,__nv=8)
 _q_t_#__D#=_q_t_+StrD(__D,__nv)+" "
EndMacro
Procedure.d PI_Double()
   !FLDPI
;    !ret
   ProcedureReturn
EndProcedure
Procedure.d somme(a.d,b.d)
  ProcedureReturn (a+b)
EndProcedure
vald.d=1000
Debug _d(pi_double())+_d(vald/pi_double())
som.d=5
For i=0 To 5
  som+somme(2,i)
  Debug _n(i)+_n(som)+_n(vald/somme(i,5))
Next


Now try these 2 prg whit always output types * .d

Code:
Macro _q_t_
  "

EndMacro
Macro _n (__n)
  _q_t_#__n#=_q_t_+Str(__n)+" "
EndMacro
Macro _d (__D,__nv=8)
 _q_t_#__D#=_q_t_+StrD(__D,__nv)+" "
EndMacro

Procedure.d Fac(n.l)
  EnableASM
  FINIT
  FLDZ
   ;si n négatif pas de combinaisons
   TEST dword [p.v_n], $80000000
   JNE fact_end1
  FLD1 ;1 dans st0
  ;si n = 0 pas de combinaisons
  CMP dword [p.v_n], 0
   JLE fact_end1
  !@@:
   ;calcule les combinaisons
   FIMUL dword [p.v_n]
   DEC dword [p.v_n]
      ;tant que n > 0
   JNZ @b
   !fact_end1:
   DisableASM
   ProcedureReturn
EndProcedure

Procedure.d Fact(n.l)
  Protected retd.d
  EnableASM
  FINIT
  FLDZ
   ;si n négatif pas de combinaisons
   TEST dword [p.v_n], $80000000
   JNE fact_end
  FLD1 ;1 dans st0
  ;si n = 0 pas de combinaisons
  CMP dword [p.v_n], 0
   JLE fact_end_loop
  !FACT_loop:
   ;calcule les combinaisons
   FIMUL dword [p.v_n]
   DEC dword [p.v_n]
      ;tant que n > 0
   JNZ FACT_loop
   !fact_end_loop:
   !fact_end:
   FSTP qword [p.v_retd]
   DisableASM
   ProcedureReturn  retd
EndProcedure

val.d=1000
For i=0 To 5
  res.d=val/fact(i); malgré des valeurs positives réelles le résultat est toujours ZERO ou 1
  factd.d=fact(i) ; il faut  passer par une variable intermédiaire pour obtenir un résultat
  Debug _n(fact(i))+_n(val/fact(i))+_n(res)+_n(factd)+_n(val/factd)+_n(i)
    res.d=val/fac(i); malgré des valeurs positives réelles le résultat est toujours ZERO ou 1
  facd.d=fac(i) ; il faut  passer par une variable intermédiaire pour obtenir un résultat
  Debug _n(fac(i))+_n(val/fac(i))+_n(res)+_n(facd)+_n(val/facd)

Next
Debug "**** avec conversion *.q c'est OK !!!!! "
 vall.q=1000  ;; avec une definition .l ou .q les résultats sont corrects
For i=1 To 5
;   Debug vall/fact(i)
  resl.q=vall/fact(i);;;; ; avec une definition .l ou .q les résultats sont corrects
  factd.d=fact(i) ;
    Debug _n(fact(i))+_n(vall/fact(i))+_n(resl)+_n(factd)+_n(vall/factd)
 Next 


Can not use the direct output of prg ASM.
It must pass through an intermediate variable.
Or convert of data *.q or * .l of val or res but does not support the type * .d
Either ASM prg is incorrect or there is an error in the output of a real number.


Last edited by PAPIPP on Thu Oct 15, 2015 7:16 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Thu Oct 15, 2015 1:53 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8149
Location: Fort Nelson, BC, Canada
None of it works here.

_________________
BERISHEET


Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Thu Oct 15, 2015 2:04 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3767
Location: Utah, USA
I have no comment on whether it is a bug or not:

There is a typo in your first code that prevents the code from compiling:
Code:
; this line: Debug _d(pi_double())+_d(vald/pi_double())
Debug _n(pi_double())+_n(vald/pi_double()) ;should look like this

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Thu Oct 15, 2015 7:07 am 
Offline
User
User

Joined: Mon Aug 17, 2009 10:48 pm
Posts: 49
Location: France
excuse me missing the macro _D

Code:
 Macro _q_t_
  "

  EndMacro
  Macro _n (__n)
  _q_t_#__n#=_q_t_+Str(__n)+" "
  EndMacro
 Macro _d (__D,__nv=8)
 _q_t_#__D#=_q_t_+StrD(__D,__nv)+" "
 EndMacro


Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Sun Oct 18, 2015 2:04 pm 
Offline
User
User

Joined: Mon Aug 17, 2009 10:48 pm
Posts: 49
Location: France
Hello everyone

After a few days and over 150 visits
No one has detected error in programming
So we have a bug. In PureBasic since at least PB420.
It's not too annoying but you have to know.


Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Sun Oct 18, 2015 7:50 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3767
Location: Utah, USA
Perhaps you can post a question to the 'Assembly Programming' Forum here and ask how to return a float value from a procedure.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Bug or programming error?
PostPosted: Thu Nov 26, 2015 5:53 am 
Offline
User
User

Joined: Sat May 10, 2008 7:52 am
Posts: 38
Location: SecondLife
TL;DR : programming error.

Your first loop go to 0 to 5
The 2nd loop go to 1 to 5

When i modify the 1st loop to go from 1 to 5 i get correct result.

1) Your code is pretty much unreadable
2) The output is horrible.
3) Comments in french (i speak french, that's why i could do it)

The modified code that works and that produce "readable" (comparable) output :

Code:
Macro _q_t_
  "

EndMacro
Macro _n (__n)
  _q_t_#__n#=_q_t_+Str(__n)+" "
EndMacro
Macro _d (__D,__nv=8)
 _q_t_#__D#=_q_t_+StrD(__D,__nv)+" "
EndMacro

Procedure.d Fac(n.l)
  EnableASM
  FINIT
  FLDZ
   ;si n négatif pas de combinaisons
   TEST dword [p.v_n], -$80000000
   JNE fact_end1
  FLD1 ;1 dans st0
  ;si n = 0 pas de combinaisons
  CMP dword [p.v_n], 0
   JLE fact_end1
  !@@:
   ;calcule les combinaisons
   FIMUL dword [p.v_n]
   DEC dword [p.v_n]
      ;tant que n > 0
   JNZ @b
   !fact_end1:
   DisableASM
   ProcedureReturn
EndProcedure

Procedure.d Fact(n.l)
  Protected retd.d
  EnableASM
  FINIT
  FLDZ
   ;si n négatif pas de combinaisons
   TEST dword [p.v_n], -$80000000
   JNE fact_end
  FLD1 ;1 dans st0
  ;si n = 0 pas de combinaisons
  CMP dword [p.v_n], 0
   JLE fact_end_loop
  !FACT_loop:
   ;calcule les combinaisons
   FIMUL dword [p.v_n]
   DEC dword [p.v_n]
      ;tant que n > 0
   JNZ FACT_loop
   !fact_end_loop:
   !fact_end:
   FSTP qword [p.v_retd]
   DisableASM
   ProcedureReturn  retd
EndProcedure

val.d=1000
For i=1 To 5
  res.d=val/fact(i)
  factd.d=fact(i)
  Debug _n(fact(i))+_n(val/fact(i))+_n(res)+_n(factd)+_n(val/factd)
 
  res.d=val/fac(i)
  facd.d=fac(i)
  Debug _n(fac(i))+_n(val/fac(i))+_n(res)+_n(facd)+_n(val/facd)
  Debug ""

Next

Debug "****"

vall.q=1000  ;; avec une definition .l ou .q les résultats sont corrects
For i=1 To 5
  resl.q=vall/fact(i);;;; ; avec une definition .l ou .q les résultats sont corrects
  factd.d=fact(i) ;
  Debug _n(fact(i))+_n(vall/fact(i))+_n(resl)+_n(factd)+_n(vall/factd)
 
  resl.q=vall/fac(i)
  facds.d=fac(i)
  Debug _n(fac(i))+_n(vall/fac(i))+_n(resl)+_n(facds)+_n(vall/facds)
  Debug "" 
Next 


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye