Post Reply 
[VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
10-08-2022, 01:38 PM (This post was last modified: 10-08-2022 02:07 PM by C.Ret.)
Post: #10
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image
Hello all,

My final version is exactly that of Valentin because like him I used semicolons for a more compact display.

2 DISP FND(3)+X;FND(1)+SIN(X);FND(4)+COS(X);FND(1)+TAN(X);FND(6)+EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF

And like Jean-François, to enter this line you must omit typing the spaces between the key words and also typing DISP which will be added automatically by the HP-71B.
It is precisely this omission that I alluded to in my previous post.

Additions are more difficult to explain. But that's also what's most exciting.
As I said before, I had a lot of trouble finding this solution and I almost gave up.

The easiest thing for me is to tell you the whole story in the correct order.


As usual, I started by reading the statement very quickly without paying attention to the details.

Like Thomas, I went immediately to a formatting solution using the operators of the IMAGE command. In spite, having read that everything had to be put on line 2, I actually went head-on into a solution using a DISP USING ...

Quickly I get a program a line resembling the one proposed above by Valentin:

2 DISP USING '9DZ.3D,11DZ.DX,8DZ.4D,11DZ.D,6DZ.6D';X,SIN(X),COS(X),TAN(X),EXP(X)+LOG(X)

Well immediately I see that it's wrong, because I'm not getting the right results and a lot of error warning messages for large numbers.


This is then I read the statement more carefully and see what is expected when the values ​​are too low or too high...
I then plan to format the result using a very complex user function that takes two arguments and returns a string. I get a DISPlay part already taking almost all available space on line 2:

2 DISP FND$(X,3);FND$(SIN(X),1);FND$(COS(X),4);FND$(TAN(X),1);FND$(EXP(X)+LOG(X),6)

At first and hoping to be able to put all the code on line 2 after having found an optimization, I add lines 10 to 19 at the end of the program to put the definition of my FNF$(V, D) function. It's a nice function full of tests IF THEN ELSE statements, etc. that manipulates character strings to form integer part, fractional part and possibly the exponent depending of the number value to display.
I will spare you the details of the 8 lines of code for this function. It is obvious that I went to a dead end, never such a structure will be able to enter the rest of the space available on line 2.

So I need to find a trick.

For everything to fit on line 2, there must necessarily be a way. Like using something that this wonderful HP-71B does naturally.

That's when I found this on page 280 of my reference manual where syntax and usage of the STR$ function is explain:
Quote:Format d'affichage à décimale fixe (FIX). La valeur est affichée en étant arrondie à n positions au-delà du signe décimal, où n est spécifié par FIX n.
Si le nombre de chiffres affichés par cette méthode dépasse 12, la valeur est affichée en format SCI n.
Si la valeur différente de zéro arrondie à n positions au-delà du signe décimal est égal à zéro, la valeur est affichée en format SCI n.

The translation is also on page 280 of the English Reference Manual, but it is also almost word for word what is specified in Valentin's statement:
   

I therefore immediately plan to use the STR$() instruction to format my values and my display function FND$ length goes from 8 lines to one single line:

10 DEF FND$(V,D) @ FIX D @ FND$=STR$(V) @ END DEF

This compact my function nicely, but still not everything is fitting in the single line 2.

I must be doing something unnecessary. As it can't be the FIX n, it has to be related to the use of the STR$().
And yes! On page 82 of the same manual the operation of DISP is explained and it's said that DISP displays numbers according to the FIX n format exactly as the STR$() instruction does.

It clicked in my little head.

2 DISP FND(X,3);FND(SIN(X),1);FND(COS(X),4);FND(TAN(X),1);FND(EXP(X)+LOG(X),6)
...
10 DEF FND(V,D) @ FIX D @ FND=V @ END DEF


Still too long, I certainly have to avoid repetition of arguments or affectations such as FND=V, etc.
So, a shorter function with a single argument definition results: FND(N) @ FIX N @ END DEF

I then erased the superfluous and prohibited lines and reentered the whole line 2. Everything entered in but with the shoehorn, ie without any spaces or the initial DISP.

2 DISP FND(3);X;FND(1);SIN(X);FND(4);COS(X);FND(1);TAN(X);FND(6);EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF


Unfortunately, this does not show the expected results but something like:
[RUN]
?_ SQRT(5) [END LINE]
 0.000  2.236  0.0  0.8  0.0000 -0.6173  0.0 -1.3  0.000000  10.161188 [END LINE]
OK
>


The solution is finally to replace the semicolons after each call to the FND function by an addition sign, which causes the unwanted zeros to disappear from the display.
2 DISP FND(3)+X;FND(1)+SIN(X);FND(4)+COS(X);FND(1)+TAN(X);FND(6)+EXP(X)+LOG(X) @ DEF FND(N) @ FIX N @ END DEF


Ah! What a challenge! That's not going to tarnish Valentin's reputation. I gave myself completely! And for once I found something decent.

In any case, a thousand thanks, I really appreciate this type of exercise, even if it takes up a lot of my leisure time.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] HP-71B Mini-challenge: Qualifying for a job II: Your best image - C.Ret - 10-08-2022 01:38 PM



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