Subject: Re: [std-proposals] new approximately equal operators
From: Eyal Rozenberg (eyalroz_at_[hidden])
Date: 2020-06-08 18:04:11
What problem would adding this behavior solve? What is its significant
If it's merely the desire to write
if (a ~= b)
if (almost_equal(a, b))
if (almost_equal<epsilon>(a, b))
(with almost_equal being a utility function you've implemented), then I
doubt the standard committee would find it worthwhile.
On 08/06/2020 22:52, Vishal Oza via Std-Proposals wrote:
> I was wonderingÂ if there is any interest in addingÂ approximately equal
> to operators into the language. The main purpose is to compare floating
> point calculations with rounding error, however they could be used for
> similarity of objects or fixed point rounded values as well.
> the operator I propose are: ~=, ~< , ~>, ~!
> theseÂ operators wouldÂ translate atÂ least to floating point as
> a ~= b ==> abs(a-b) <Â epsilon
> a ~< b ==> (a < b) || (abs(a-b) <Â epsilon)
> Â a ~> b ==> (a > b) || (abs(a-b) <Â epsilon)
> a ~! b ==> abs(a-b) >=Â Â epsilon
> There are two routes I can see with default implementation this language
> feature. either adding a defaultÂ epsilonÂ into the language that can be
> set as a global variableÂ or adding some way of tracking errors. I would
> like more feedback on either way of default implementation.
> I would also like a way to specifyÂ the epsilonÂ value or function for a
> single comparison. the best I can think of is
> a ~=b(c) ==>Â abs(a-b) <Â c
> a ~=b:c ==>Â abs(a-b) <Â c
> [c]a ~=b ==>Â abs(a-b) <Â c
> The precedence should be on the same level of all of the current
> comparisonÂ operators.
> This could be introduced in C++ 23 or later in there is any interate.
> Vishal Oza
> *This email is from an external mail server, be judicious when opening
> attachments or links *
STD-PROPOSALS list run by email@example.com
Standard Proposals Archives on Google Groups