[Development] Should QVariant be doing fuzzy comparisons on doubles?
Edward Welbourne
edward.welbourne at qt.io
Fri Sep 23 11:56:30 CEST 2016
Olivier Goffart
> What use case did you have in mind where a reflexive relation is any usefull?
Well, having x == x for all x is generally considered a useful property
of equality. That's all "reflexive" is saying.
> There is the case of the key of a QHash or in a QSet, but even then i'm not
> sure it is wise that all QVariant of the same type map to the "same" value.
Indeed; having all values of some type equivalent is worse (for the "has
my value changed" test you illustrate, at least) than having a value not
equal to itself (which triggers a "changed" event for a non-change). In
fact one can have one's mathematical purity by attacking the "for all x"
part of the above instead of the "x == x" part. Although it's usual to
talk about "a relation is reflexive on S if, for all s in S, it relates
s to s" one can equally define reflexive by "whenever the relation
relates any x to y, it also relates x to x and y to y". (This is the
more natural formulation in a mathematics based on relations [*] rather
than sets.)
[*] http://www.chaos.org.uk/~eddy/maths/found/relate.xhtml#Types
With that formulation (which doesn't tie the relation to a set that it's
"on"), returning false for the types that don't support equality
comparison works; we won't consider any value of such a type equal to
*anything*, so our relation isn't required to relate them to themselves.
We are then left with QVariant::operator== being a relation formally on
only those QVariants that support comparison, not on all QVariants
(although it tolerates being asked about the values it doesn't relate to
anything; it just says no about them).
It's not ideal (and the justification is heterodox) but false is a valid
answer for the incomparable values,
Eddy.
More information about the Development
mailing list