Eliminate the baroque floating-point operators a la !<>=

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Sun May 17 12:44:57 PDT 2009


Andrei Alexandrescu wrote:

> I think the floating-point operators:
> 
>    a !<>= b
>    a !<> b
>    a <> b
>    a <>= b
>    a !> b
>    a !>= b
>    a !< b
>    a !<= b
> 
> are useless.

Actually, I like the concept of comparison operators for partial orders.
When I first read the D1 specs, this set of operators was one of the
features I especially liked.

However, at the time I didn't realise they were solely for floating point
numbers. They would make more sense if they could be overloaded.

For example, they can be used for multi-objective optimization. With more
than one objective, you need a way to express comparability of two
potential solutions (<>= means comparable).

They would be good for expressing the subset relation, where < is the strict
subset relation and A <>= B would express that one of A and B is a subset
of the other.

Logically, they would be defined for the Boolean truth-values. False and
true are incomparable to each other, but equal to themselves.

And for those people that don't (want to) know about all of these extra
operators, they don't have to. What's more, when it comes to integers, <>
and != are equivalent, which is nice for those programmers that are
familiar with one, but not the other.

There's this thing, though. I would make it so !(a op b) is equivalent to
(a !op b). It's a nice property. The IEEE standard requires that you set a
certain exception flag when comparing with a NaN value, right? Well, just
set the flag with the extra operators as well. The !(a op b) = (a !op b)
thing can even be extended to the and/or/xor operators.

I know that most of these operators don't make sense with integers and
booleans. But you can give a compiler warning when you have a comparison
with a predictable return value.

In fact, everything I've said here is part of the Mist programming language.
Inspired by D's example. :-)

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list