| Gottfried Helms on Sat, 05 Nov 2022 23:43:22 +0100 | 
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Bug in evaluating "if(p==[],...)" | 
This is a funny bug.
I have a function with two arguments (p,q);
 - if in argument p is a scalar value, a vector in q is expected,
 - if in p is a vector, in q is a scalar expected.
 The vectors can be empty (p=[] or q=[]), their type being vector
 simply indicates, that some specific sequel has to be worked.
Here is the maximally reduced function:
{testfindroots_pq(p=[],q=[]) = my();
    if(p==[]
       ,print("p=",p," q=",q," ---> heading in p==[] path  ");
       ,print("p=",p," q=",q," ---> heading in p<>[] path  ");
      ); }
Here the result:
testfindroots_pq([],1) \\ p=[] q=1 ---> heading in p==[] path        +++ correct
testfindroots_pq([],0) \\ p=[] q=0 ---> heading in p==[] path        +++ correct
testfindroots_pq(1,[]) \\ p=1 q=[] ---> heading in p<>[] path        +++ correct
testfindroots_pq(0,[]) \\ p=0 q=[] ---> heading in p==[] path        ***** false *****
The problem is here, that supplying the scalar integer value "0" is
taken as "==[]" (but not for instance the integer value "1")
Just to note for this tiny bug.
-----------------------------------------------------------------------------------
A correctly working version is of course the more explicite
{testfindroots_pq(p=[],q=[]) = my();
   if(type(p)=="t_VEC"  \\ <-- this works correctly
       ,print("p=",p," q=",q," ---> heading in p==[] path ");
       ,print("p=",p," q=",q," ---> heading in p<>[] path ");
     ); }
Gottfried Helms