Skip to content

Commit 2d61599

Browse files
authored
Merge pull request #93 from GaragePixel/develop
Add bool/bool8 ternary operator's result conversion
2 parents d8c47e2 + 1ce741a commit 2d61599

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

modules/std/types/bools.xw

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ Alias BoolArray:Bool[] 'Added iDkP 2025-07-09!
2121

2222
'---------------------- Utils: Old Bool type
2323

24+
#rem wonkeydoc Bool to Ternary.
25+
@author iDkP from GaragePixel
26+
@since 2025-07-21
27+
Implicite conversion from bool to int is possible. In this case:
28+
- if v=True return 1
29+
- if v=False return 0
30+
But this function is special:
31+
- if v=True return 1
32+
- if v=False return -1
33+
... as it's intented to be used to cast a binary compare functions, sometimes with a sort.
34+
#end
35+
Function BoolToTernary:Int( v:Bool )
36+
'if v=true return 1
37+
'if v=false return -1
38+
Return v=False ? -1 Else v
39+
End
40+
2441
Function Is:Bool(a:Bool)
2542
'Deprecated int32 boolean version, for the reciprocal
2643
Return a=True

modules/std/types/composites/bool8.xw

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,24 @@ Const True8:Bool8=$1
194194
' version for the old Bool data type, per example NandBool(False,False) who will returns a heavy int32 as boolean,
195195
' but Nand:Bool8(False,False) will returns a light byte as boolean.
196196

197-
' Conversion from/to the old bool type
197+
' Conversion from/to the old bool type and ternary operator's result
198+
199+
#rem monkeydoc Bool8 to Ternary.
200+
@author iDkP from GaragePixel
201+
@since 2025-07-21
202+
Implicite conversion from bool to int is possible. In this case:
203+
- if v=True8 return 1
204+
- if v=False8 return 0
205+
But this function is special:
206+
- if v=True8 return 1
207+
- if v=False8 return -1
208+
... as it's intented to be used to cast a binary compare functions, sometimes with a sort.
209+
#end
210+
Function Bool8ToTernary:Int( v:Bool8 )
211+
'if v=true return 1
212+
'if v=false return -1
213+
Return v=False8 ? -1 Else v
214+
End
198215

199216
Function FromBool:Bool8(this:Bool)
200217
Return Cast<Bool8>(this)

0 commit comments

Comments
 (0)