# Confused about comparisons of vectors Classic List Threaded 9 messages Open this post in threaded view
|

## Confused about comparisons of vectors

 According to the manual, a comparison of vectors is true if it is true pointwise.   But I am having trouble finding a situation where a comparison of inequalities is true.   echo([1,2] < [1,2]);    // false echo([1,2] == [1,2]);   // true echo([1,2] < [10,10]);  // false but I expected true Can somebody clarify this for me?   -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Confused about comparisons of vectors

 Looks like vectors are only equality comparable and not less than comparable. I think it ends up using boost variant, so I don't know how easy it is to fix.On Mon, 8 Apr 2019 at 22:27, adrianv <[hidden email]> wrote:According to the manual, a comparison of vectors is true if it is true pointwise.   But I am having trouble finding a situation where a comparison of inequalities is true.  echo([1,2] < [1,2]);    // false echo([1,2] == [1,2]);   // true echo([1,2] < [10,10]);  // false but I expected true Can somebody clarify this for me?  -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Confused about comparisons of vectors

Open this post in threaded view
|

## Re: Confused about comparisons of vectors

 Ok, so the correct definition of the behavior is that inequality tests between lists always return false?   -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Confused about comparisons of vectors

 In reply to this post by adrianv ```echo([1,2] < [1,2]); // false echo([1,2] == [1,2]); // true echo([1,2] < [10,10]); // false but I expected true``` I'm not clear what a greater/less comparison would mean, but one of the key aspects of a "normal" comparison is that one value is either less, equal, or greater than another. It seems that's not the case for vectors.     If you have two vectors a and b that are not equal, a is neither less than b nor greater than b: a=[1,1]; b=[2,2]; echo(lt = a < b); echo(eq = a == b); echo(gt = a > b); results in ECHO: lt = false ECHO: eq = false ECHO: gt = false ... so whatever it's doing, it's not a conventional comparison. In fact, "less or equal" and "greater or equal" don't seem to include "equal": a=[1,1]; b=[1,1]; echo(lt = a < b); echo(lt = a < b); echo(le = a <= b); echo(eq = a == b); echo(ge = a >= b); echo(gt = a > b); yields: ECHO: lt = false ECHO: le = false  <<< ECHO: eq = true   <<< ECHO: ge = false  <<< ECHO: gt = false Results are the same even for single-entry vectors. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Confused about comparisons of vectors

 In reply to this post by adrianv On 09.04.19 01:22, adrianv wrote: > Ok, so the correct definition of the behavior is that inequality > tests between lists always return false? I don't know if that's correct, but looking at the code, that is how it's implemented. How would a matrix of all possible combinations (of types) look like? ciao,    Torsten. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

## Re: Confused about comparisons of vectors

 tp3 wrote > On 09.04.19 01:22, adrianv wrote: >> Ok, so the correct definition of the behavior is that inequality >> tests between lists always return false? > > I don't know if that's correct, but looking at the code, that is > how it's implemented. > > How would a matrix of all possible combinations (of types) look > like? I'm not asking for any kind of change---just trying to understand the behavior. If I were going to propose a change I would say that it would be better to simply return an error or undef instead of always returning false.   Are you asking what does the matrix of types for inequalities look like, such as if you compare a boolean to a number or a number to a list or a range?   I personally would say that incompatible combinations should be an error or undef (so any mixed combination of string, number and boolean).   In fact, I discovered that "false<3" evaluates to true, which is sort of strange.  And apparently "true>false" is true.  It looks like false=0 for purposes of inequality comparisons---but not equality.   And true=1.  I would say it's better that these tests give an error, or undef. Testing a string against a number seems to give false in all cases---again I would suggest than an error or undef would be better.   The question of hows lists are handled is sort of different since lists can contain all the other types.  I would suggest that there are two choices that make sense for "list > list" where the lists have the same length. Either the result is a new list of individual comparisons (like in MATLAB) or the result is (as erroneously documented in the wiki), true if the elementwise comparisons are all true.   When the lists have incompatible lengths it seems debatable, but I'd suggest that undef makes the most sense.   -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org