Post Reply 
SIGN Function
01-04-2017, 08:19 AM
Post: #1
SIGN Function
Hi and happy new year !

A question (may be stupid).
Why the test in attachement is not running ?

If only one OR two OR the three SIGN is zero ===> "DATE ??"
If no SIGN equal zero ===> "DATE OK"

Gérard.
Find all posts by this user
Quote this message in a reply
01-04-2017, 10:58 AM
Post: #2
RE: SIGN Function
When you use the parameters to define a function, you are ready to use them without declaring them with LOCAL.

Otherwise, the input parameters are uniquely used by the new local variables defined in line 3, although they are called equal, they are different.

delete line: LOCAL J,M,A;

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-04-2017, 11:04 AM (This post was last modified: 01-04-2017 11:10 AM by DrD.)
Post: #3
RE: SIGN Function
First, please include the program, (so that we can copy/paste it into our conn kit). You can do that by using the hash tag on the right side of the message editor toolbar.

Second, your image cuts off the conditional action on the IF THEN ELSE END; branch. I'll take a guess at that ...

Third, as shown, you are missing an END; statement that terminates the conditional structure.

Fourth, you don't need the "LOCAL" definition, since you have declared the variables on entry, in the program calling structure. OKDATE(J,M,A) .... However, you are using reserved variables. You should read about them in the guides, to fully understand this reservation.

Fixing ONLY the syntax error in the image, (it might be there but just not shown is a missing "End;"), here is the result:

Code:

EXPORT OKDATE(J,M,A)
BEGIN
  LOCAL J,M,A;

  IF SIGN(J) OR SIGN(M) OR SIGN(A) == 0 THEN
    PRINT("DATE ??");
  ELSE
    PRINT("DATE OK");
  END;
  
END;

You might want to work through the rest of the program, yourself; but feel free to ask, if you want further suggestions.
HINT:
You can insert/remove DEBUG; or KILL; statements along the way, to check the consequence of a procedure.
You can make use of those reserved variables on the command line, to check the results from statements, or procedures.
You can clear the terminal screen by first using a PRINT(); if you want to start with a blank screen.
You can use comment markers, "//" commenting out commands to temporarily remove them, if need be: // LOCAL J,M,A; for example.


-Dale-
Find all posts by this user
Quote this message in a reply
01-04-2017, 11:38 AM
Post: #4
RE: SIGN Function
Code:
EXPORT OKDATE(J,M,A)
BEGIN
LOCAL J,M,A;


IF (SIGN(J) OR SIGN(M) OR SIGN(A))==0
 
THEN PRINT("Date ??")
ELSE PRINT("Date OK");
END;

END;

It is my progrm wrong.

Normaly if only one test is wrong than the date is wrong.

Gérard.
Find all posts by this user
Quote this message in a reply
01-04-2017, 11:55 AM
Post: #5
RE: SIGN Function
Well, you've bumped into an interesting situation there ...
There is a missing semicolon on the PRINT("Date ??") <==
BUT, the compiler doesn't pick up the syntax error. <BUG discovered>.

Another approach, just for fun:

Code:

EXPORT OKDATE(J,M,A)
BEGIN
  IFTE( (SIGN(J) OR SIGN(M) OR SIGN(A))==0,PRINT("Date ??"), PRINT("Date OK") );
END;

-Dale-
Find all posts by this user
Quote this message in a reply
01-04-2017, 12:19 PM
Post: #6
RE: SIGN Function
It is always the same result : Date OK

if I write 23 2 1935
or 0 2 1935
or 23 0 1935
or 23 2 0

I obtain "Date OK" !!!

I was wanted a sort cut, but ...

Gérard.
Find all posts by this user
Quote this message in a reply
01-04-2017, 03:12 PM
Post: #7
RE: SIGN Function
Not sure I understand why you are using SIGN() here as you are testing if it’s equal to 0 which occurs only is the parameters itself equals to 0.
So you can do: IF J==0 OR M==0 OR A==0 THEN …
And even more simple a single test will do the same thing: IF J*M*A==0 THEN … as J*M*A will be equal to zero if at least one of J, M or A is equal to zero.

So in a concise way:
Code:
EXPORT OKDATE(J,M,A)
BEGIN
  IFTE( J*M*A,PRINT("Date OK"),PRINT("Date ??") );
END;

If J*M*A is not zero (True condition) the first PRINT is executed, if it's zero (False condition) it's the second one.
Find all posts by this user
Quote this message in a reply
01-04-2017, 03:34 PM
Post: #8
RE: SIGN Function
Thank you all, it is the better way in multiplication J M A, of course, but Iwas not thinked of this.

Thanks, but I dont' understand why test with "SIGN()" dont' run.

Gérard.
Find all posts by this user
Quote this message in a reply
01-04-2017, 04:10 PM (This post was last modified: 01-04-2017 04:11 PM by Didier Lachieze.)
Post: #9
RE: SIGN Function
(01-04-2017 03:34 PM)ggauny@live.fr Wrote:  Thanks, but I dont' understand why test with "SIGN()" dont' run.

In the program from Dale:

Code:
EXPORT OKDATE(J,M,A)
BEGIN
  IFTE( (SIGN(J) OR SIGN(M) OR SIGN(A))==0,PRINT("Date ??"), PRINT("Date OK") );
END;

The test is not written correctly: (SIGN(J) OR SIGN(M) OR SIGN(A) ) will be equal to zero ONLY if J and M and A are all equal to zero, if one value is not equal to zero then the result of the OR will not be equal to zero.
Find all posts by this user
Quote this message in a reply
01-04-2017, 04:19 PM (This post was last modified: 01-04-2017 04:21 PM by StephenG1CMZ.)
Post: #10
RE: SIGN Function
(01-04-2017 12:19 PM)ggauny@live.fr Wrote:  It is always the same result : Date OK

if I write 23 2 1935
or 0 2 1935
or 23 0 1935
or 23 2 0

I obtain "Date OK" !!!

I was wanted a sort cut, but ...

To explain why it is not working: your program logic is not correct.
These examples all yield the same answer:

Sign of 23 2 95 is 1 or 1 or 1 which is 1==0
Sign of. 0 2 95 is 0 or 1 or 1 which is 1
Sign of 23 0 95 is 1 or 0 or 1 which is 1
Sign of 23 2 0 is 1 or 1 or 0 which is 1

Sign of 0 0 0 is 0 or 0 or 0 which is 0==0 (the only time your date is not ok)

The sign generates 0 if the input is 0
The Or generates 0 only if every input is 0, otherwise its 1.

To check if J A M are all nonzero you could use
If J AND A AND M // Prime treats 0 as false
THEN PRINT("Date maybe ok"); //All three nonzero
// dont forget many other invalid dates exist, eg 33 3 95
ELSE PRINT("At least one 0");
END;//IF

Hope that makes it clearer

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
01-05-2017, 06:26 AM
Post: #11
RE: SIGN Function
Hello,

<Quote>
Well, you've bumped into an interesting situation there ...
There is a missing semicolon on the PRINT("Date ??") <==
BUT, the compiler doesn't pick up the syntax error. <BUG discovered>.
</Quote>

Nope, not a bug.
';' are (like in Pascal), instruction SEPARATORS. So they are only needed to separate 2 instructions.
then, else, end... are keywords, not instructions, so ; are not necessary for the last instruction before them.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
01-05-2017, 12:38 PM
Post: #12
RE: SIGN Function
Well I'll be darned ... old pooch got'em new trick! Thanks.

No semi's ... I'm semi satisfied with that answer. Semi satisfied: while it works, I don't think I would want to adopt this as a good programming practice. It's enough just remembering to include ";" where they ARE needed! Smile

Code:

EXPORT example1()
BEGIN

 IF N==0 THEN
   RETURN
 ELSE
   RETURN
 END

END;
Find all posts by this user
Quote this message in a reply
01-09-2017, 06:56 AM
Post: #13
RE: SIGN Function
Hello,

Both systems work (semi as terminator and semi as separator) from the compiler standpoint.

When I made the PPL compiler, I did not need to force the addition of the semi, so I did not...

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
01-09-2017, 10:33 AM
Post: #14
RE: SIGN Function
Thanks for the background detail on it. Somewhere along the line, I adopted the idea of 'required' semi's for all completed statements. No requirement for semi, in this case doesn't change any practice FOR using them, so I can see how it's not really a bug.

It's very helpful to have your explanations, and I appreciate your willingness to share them!

-Dale-
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)