Bug or programming error?

Bare metal programming in PureBasic, for experienced users
PAPIPP
User
User
Posts: 49
Joined: Mon Aug 17, 2009 10:48 pm
Location: France

Bug or programming error?

Post by PAPIPP »

Bug or programming error ?
Here are 2 prg that work properly

Code: Select all

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: Select all

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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Bug or programming error?

Post by netmaestro »

None of it works here.
BERESHEIT
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Bug or programming error?

Post by Demivec »

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: Select all

; this line: Debug _d(pi_double())+_d(vald/pi_double())
Debug _n(pi_double())+_n(vald/pi_double()) ;should look like this
PAPIPP
User
User
Posts: 49
Joined: Mon Aug 17, 2009 10:48 pm
Location: France

Re: Bug or programming error?

Post by PAPIPP »

excuse me missing the macro _D

Code: Select all

 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
PAPIPP
User
User
Posts: 49
Joined: Mon Aug 17, 2009 10:48 pm
Location: France

Re: Bug or programming error?

Post by PAPIPP »

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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Bug or programming error?

Post by Demivec »

Perhaps you can post a question to the 'Assembly Programming' Forum here and ask how to return a float value from a procedure.
ker2x
User
User
Posts: 38
Joined: Sat May 10, 2008 7:52 am
Location: SecondLife

Re: Bug or programming error?

Post by ker2x »

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: Select all

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  
Post Reply