From ba5a39a9c46cf0d21cb0c2fdfd3a1c532583c0e2 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Mon, 21 Jul 2025 05:08:08 +0200 Subject: [PATCH 1/2] Update bools.xw --- modules/std/types/bools.xw | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/std/types/bools.xw b/modules/std/types/bools.xw index 756a60a2..65b3a016 100644 --- a/modules/std/types/bools.xw +++ b/modules/std/types/bools.xw @@ -21,6 +21,23 @@ Alias BoolArray:Bool[] 'Added iDkP 2025-07-09! '---------------------- Utils: Old Bool type +#rem wonkeydoc Bool to Ternary. +@author iDkP from GaragePixel +@since 2025-07-21 +Implicite conversion from bool to int is possible. In this case: +- if v=True return 1 +- if v=False return 0 +But this function is special: +- if v=True return 1 +- if v=False return -1 +... as it's intented to be used to cast a binary compare functions, sometimes with a sort. +#end +Function BoolToTernary:Int( v:Bool ) + 'if v=true return 1 + 'if v=false return -1 + Return v=False ? -1 Else v +End + Function Is:Bool(a:Bool) 'Deprecated int32 boolean version, for the reciprocal Return a=True From 1ce741a433603bef6d84f506941b118e9db20ca3 Mon Sep 17 00:00:00 2001 From: GaragePixel Date: Mon, 21 Jul 2025 05:10:41 +0200 Subject: [PATCH 2/2] Update bool8.xw --- modules/std/types/composites/bool8.xw | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/std/types/composites/bool8.xw b/modules/std/types/composites/bool8.xw index d09bf92e..3470f615 100644 --- a/modules/std/types/composites/bool8.xw +++ b/modules/std/types/composites/bool8.xw @@ -194,7 +194,24 @@ Const True8:Bool8=$1 ' version for the old Bool data type, per example NandBool(False,False) who will returns a heavy int32 as boolean, ' but Nand:Bool8(False,False) will returns a light byte as boolean. -' Conversion from/to the old bool type +' Conversion from/to the old bool type and ternary operator's result + +#rem monkeydoc Bool8 to Ternary. +@author iDkP from GaragePixel +@since 2025-07-21 +Implicite conversion from bool to int is possible. In this case: +- if v=True8 return 1 +- if v=False8 return 0 +But this function is special: +- if v=True8 return 1 +- if v=False8 return -1 +... as it's intented to be used to cast a binary compare functions, sometimes with a sort. +#end +Function Bool8ToTernary:Int( v:Bool8 ) + 'if v=true return 1 + 'if v=false return -1 + Return v=False8 ? -1 Else v +End Function FromBool:Bool8(this:Bool) Return Cast(this)