Date: Fri, 24 Nov 2023 12:36:32 +0100
Bikeshed:
The corner brackets (0x300c, 0x300d) perhaps.
double absa = 「a」;
I would have rather liked, if brackets for abs would have a vertical symmetry axis (than the rotational symmetry).
However, I agree with Tom: if we were going to add more operators to the language, this wouldn't be my first choice.
-----Ursprüngliche Nachricht-----
Von:Tom Honermann via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Fr 24.11.2023 05:31
Betreff:Re: [std-proposals] Unary operator | (absolute value of)
An:std-proposals_at_[hidden];
CC:Tom Honermann <tom_at_[hidden]>;
I don't see a lot of motivation for this feature, but if we were to pursue a notation for this, a bracket notation would allow more expressiveness and would be more inline with common mathematical notation.
int a = ...;
int b = ...;
int c = |b-a|;
Unfortunately, '|' (U+007C VERTICAL LINE) isn't available to be repurposed like this. There are a couple of other options.
' ∣' (U+2223 DIVIDES) is available, but it isn't intended for use as an absolute value symbol and its similarity to U+007C makes use of it a questionable choice.
'‖' (U+2016 DOUBLE VERTICAL LINE) is available, but that character is generally used to express a mathematical norm and that is not the same as the absolute value.
None of these options provides distinct characters for left vs right ends of the notation, so would require parenthesis when nested.
Other Unicode characters could of course be employed for a new syntax, but meh, abs() already exists and if we were going to add more operators to the language, this wouldn't be my first choice.
Tom.
On 11/23/23 5:43 PM, Rik van der Brugghen via Std-Proposals wrote:
Hi.
Maybe suggested before, but would be great with
a = |b; // a = abs (b)
That's it, exactly same semantic behaviour (precedence and all that stuff) as ~b.
Best regards,
Rik van der Brugghen
Stockholm
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2023-11-24 11:36:34