[Scilab-users] Booeleans : irrelevant results ?

Carrico, Paul paul.carrico at esterline.com
Thu Aug 27 13:36:21 CEST 2015


Effectively it is much better to use isempty() function (or ~isempty() in the current case) … I didn’t know it so far

Many thanks for your help

Paul

EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data

De : Pierre Vuillemin [mailto:contact at pierre-vuillemin.fr]
Envoyé : jeudi 27 août 2015 13:08
À : Users mailing list for Scilab
Cc : Carrico, Paul
Objet : Re: [Scilab-users] Booeleans : irrelevant results ?


Dear Paul,

The behaviour of test 2 may come from the order in which the operations are performed :



Note that (a & c & b) ~= (b & c & a), indeed :

- a & c & b performs a & c which returns [] and then [] & b which returns [],

- b & c & a performs b & c which returns %t and then %t & [] which returns %t.

You can obtain the desired behaviour by adding parenthesis

b & (c & a) returns []

but it may be safer to use isempty() to check whether a variable is empty or not.



Best regards,



Pierre



Le 27.08.2015 12:29, Carrico, Paul a écrit :
Dear All,

I wondering what I’m doing wrong in the examples here bellow:

-          Test 1 --> M returns False that’s ok for me

-          Test 2 --> should return False as well, shouldn’t be ?

-          Test 3 --> another test using directly a Boolean instead of an empty form []

-          Test 4 --> as expected, it returns F

Thanks for any highlight

Paul

##############################################################################”
mode(0)

// test 1
M = [];
if M then
    printf("M returns T\n");
else
    printf("M returns F\n");
end

// test 2
a=[];
b=30;
c=200;

if (b & c & a) then
    printf("val = 6\n");
    else printf("val = []\n"); // should return [] ??????
end

// test 3
tmp = %f;
//tmp = %t;

if (tmp) then
    printf("tmp returns T\n");
else
    printf("tmp returns F\n");
end

// test 4
t1 = %t;
t2 = %t;
//t3 = %t;
t3 = %f;

if (t1 & t2 & t3) then
    printf("(t1,t2,t3) returns T\n");
else
    printf("(t1,t2,t3) returns F\n");
end

EXPORT CONTROL :
Cet email ne contient pas de données techniques
This email does not contain technical data


_______________________________________________
users mailing list
users at lists.scilab.org<mailto:users at lists.scilab.org>
http://lists.scilab.org/mailman/listinfo/users<https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.scilab.org_mailman_listinfo_users&d=AwMFaQ&c=0hKVUfnuoBozYN8UvxPA-w&r=4TCz--8bXfJhZZvIxJAemAJyz7Vfx78XvgYu3LN7eLo&m=CsJzSea7OehSm_fgX8J6czbmq4kUd-ws1o3meFqpHek&s=EFhyGA5WXCbkAbKVE545SI6VDStjViqsaNYDJ3bW3uw&e=>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20150827/e306a31c/attachment.htm>


More information about the users mailing list