Date: Thu, 4 Sep 2025 23:02:15 +0200
On 04/09/2025 18:41, Bjorn Reese via Std-Proposals wrote:
> On 9/4/25 16:39, David Brown via Std-Proposals wrote:
>
>> I had meant to explicitly cast to int, but was missing some
>> parentheses (because your code has questionable use of parentheses,
>> and I was not paying enough attention) :
>>
>> return int(x >= T(0)) - int(x <= T(0));
>
> Apologies for the missing paranthesis in my code. However, that is not
> the issue. The issue is that if T is a SIMD type, then the comparison
> returns a mask containing multiple answers. Casting to int (if T has
> an approriate conversion operator) and subtracting the scalar values
> gives the wrong result. Casting to T gives the right result.
>
>> It is, however, not unknown for people to use "(x >= 0) - (x <= 0)" as
>> a way to calculate the sign of a scalar integer. And there, explicit
>> casts to int as I wrote (or tried to write!) would work just as well
>> as implicit casts from bool to int.
>
> You are arguing for the removal of implicit bool casts, but this has
> implications for generic code as I have shown.
>
No, you have not. What you have shown is that in code that does not use
bool types, you may or may not need casts, depending on how the types
you use are defined.
I do agree that the removal of implicit conversions between bool and
int, in either direction, would affect some kinds of real-world code.
Such code would need explicit conversions added - but not in a
particularly difficult or unreasonable manner.
> On 9/4/25 16:39, David Brown via Std-Proposals wrote:
>
>> I had meant to explicitly cast to int, but was missing some
>> parentheses (because your code has questionable use of parentheses,
>> and I was not paying enough attention) :
>>
>> return int(x >= T(0)) - int(x <= T(0));
>
> Apologies for the missing paranthesis in my code. However, that is not
> the issue. The issue is that if T is a SIMD type, then the comparison
> returns a mask containing multiple answers. Casting to int (if T has
> an approriate conversion operator) and subtracting the scalar values
> gives the wrong result. Casting to T gives the right result.
>
>> It is, however, not unknown for people to use "(x >= 0) - (x <= 0)" as
>> a way to calculate the sign of a scalar integer. And there, explicit
>> casts to int as I wrote (or tried to write!) would work just as well
>> as implicit casts from bool to int.
>
> You are arguing for the removal of implicit bool casts, but this has
> implications for generic code as I have shown.
>
No, you have not. What you have shown is that in code that does not use
bool types, you may or may not need casts, depending on how the types
you use are defined.
I do agree that the removal of implicit conversions between bool and
int, in either direction, would affect some kinds of real-world code.
Such code would need explicit conversions added - but not in a
particularly difficult or unreasonable manner.
Received on 2025-09-04 21:02:19