[Done] Boolean expressions with string functions

All bugs related to new C backend
Geert
User
User
Posts: 30
Joined: Thu Aug 16, 2012 3:17 pm
Location: Belgium
Contact:

[Done] Boolean expressions with string functions

Post by Geert »

C backend: when using string functions in boolean expressions (If/Bool with And/Or) the results are not always correct.
ASM backend: no problem.

Code: Select all

Debug "***And***"

s.s="{test}"

If Left(s,1)="{" And Right(s,1)="}"
 Debug "True"
Else
 Debug "False"
EndIf 

If Left(s,1)="{"
 If Right(s,1)="}"
  Debug "True"
 Else
  Debug "False"
 EndIf
Else
 Debug "False"
EndIf 

sl.s=Left(s,1)
sr.s=Right(s,1)
If sl="{" And sr="}"
 Debug "True"
Else
 Debug "False"
EndIf 

Debug Bool(Left(s,1)="{")
Debug Bool(Right(s,1)="}")
Debug Bool(Left(s,1)="{" And Right(s,1)="}")
Debug Bool(Left(s,1)="{") & Bool(Right(s,1)="}")

Debug Bool(sl="{" And sr="}")
Debug Bool(sl="{") & Bool(sr="}")

a=Bool(Left(s,1)="{")
b=Bool(Right(s,1)="}")

Debug a & b

Debug "***Or***"

s="{test"

If Left(s,1)="{" Or Right(s,1)="}"
 Debug "True"
Else
 Debug "False"
EndIf 

sl=Left(s,1)
sr=Right(s,1)
If sl="{" Or sr="}"
 Debug "True"
Else
 Debug "False"
EndIf 

Debug Bool(Left(s,1)="{")
Debug Bool(Right(s,1)="}")
Debug Bool(Left(s,1)="{" Or Right(s,1)="}")
Debug Bool(Left(s,1)="{") | Bool(Right(s,1)="}")

Debug Bool(sl="{" Or sr="}")
Debug Bool(sl="{") | Bool(sr="}")

a=Bool(Left(s,1)="{")
b=Bool(Right(s,1)="}")

Debug a | b
C backend output:
***And***
False
True
True
1
1
0
0
1
1
1
***Or***
False
True
1
0
0
0
1
1
1
ASM backend (v6, v5.73) output:
***And***
True
True
True
1
1
1
1
1
1
1
***Or***
True
True
1
0
1
1
1
1
1
Fred
Administrator
Administrator
Posts: 14413
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Boolean expressions with string functions

Post by Fred »

Fixed.
Little John
Addict
Addict
Posts: 4007
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [Done] Boolean expressions with string functions

Post by Little John »

Fred,

in PB 6.0 alpha 2, there are still problems with string functions in a Boolean expression.

Code: Select all

Debug Bool("Pear" > "apple")
Debug Bool("PEAR" > "APPLE")
Debug Bool(UCase("Pear") > UCase("apple"))
Output when using the ASM backend (all correct):
0
1
1
Output when using the C backend:
0
1
0 <== BUG
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
Little John
Addict
Addict
Posts: 4007
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: [Done] Boolean expressions with string functions

Post by Little John »

@Fred: It's NOT done!
Still the same wrong result with my above code when using PB 6 alpha 3.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
juergenkulow
User
User
Posts: 64
Joined: Wed Sep 25, 2019 10:18 am

Re: Boolean expressions with string functions

Post by juergenkulow »

Code: Select all

; Bool string function compare
Define u1.u, u2.u,*p0,*p1
b= Bool(UCase("P") > UCase("a"))
b2=Bool(LCase("P") > LCase("a")) 
CompilerIf #PB_Backend_C=#PB_Compiler_Backend
  ! v_u1=_S1[0]; 
  ! v_u2=_S2[0];
  ! p_p0=p0;
  ! p_p1=p1;
  s.s="PB_Backend_C   b:"+Str(b)+" b2:"+Str(b2)+" u1:"+Str(u1)+" u2:"+Str(u2)+" p0:"+Hex(*p0)+" p1:"+Hex(*p1)
CompilerElse
  s.s="PB_Backend_ASM b:"+Str(b)+" b2:"+Str(b2)
CompilerEndIf 
SetClipboardText(s)
; PB_Backend_ASM b:1 b2:1
; PB_Backend_C   b:0 b2:0 u1:80 u2:97 p0:0 p1:4

; // b= Bool(UCase("P") > UCase("a"))
; SYS_PushStringBasePosition();
; SYS_PushStringBasePosition();
; PB_UCase(_S1,SYS_PopStringBasePosition());
; PB_StringBasePosition+=2;
; SYS_PushStringBasePosition();
; SYS_PushStringBasePosition();
; PB_UCase(_S2,SYS_PopStringBasePosition());
; ;
; void* p0=SYS_PopStringBasePositionValue();
; void* p1=SYS_PopStringBasePositionValue();
; v_b=((SYS_StringSuperior(p1,p0))?1:0);
Fred
Administrator
Administrator
Posts: 14413
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Boolean expressions with string functions

Post by Fred »

Fixed.
Post Reply