Should you be able to initialize a float with a char?
Walter Bright
newshound2 at digitalmars.com
Thu May 19 04:35:45 UTC 2022
On 5/18/2022 5:47 PM, Steven Schveighoffer wrote:
> But I have little hope for it, as Walter treats a boolean as an integer.
They *are* integers.
The APL language relies on bools being integers so conditional operations can be
carried out without branching :-)
I.e.
a = (b < c) ? 8 : 3;
becomes:
a = 3 + (b < c) * 5; // I know this is not APL syntax
That works in D, too!
Branchless code is a thing, it is used in GPUs, and in security code to make it
resistant to timing attacks.
You'll also see this in the SIMD instructions, although they set all bits
instead of just 1, because & is faster than *.
a = 3 + (-(b < c) & 5);
More information about the Digitalmars-d
mailing list