Post Reply 
HP49-50G Square root many (50 or more) digits
04-24-2021, 11:08 PM
Post: #1
HP49-50G Square root many (50 or more) digits
HP49-50G Square root many digits

Of course there are plenty ways of calculating the square root.

Here is a sequence of commands included in one single program that can be used as a user-assigned key.

ROOT2
\<< "\[] 1 Arg

\[] Put below 101 if
you want 100 digits
" DROP 51 \-> digit
\<< -105 CF DUP "\v/" SWAP + SWAP DUP \v/ SWAP DUP \->STR SWAP FP \-> nb f
\<<
IF f 0 \=/
THEN nb "." POS 1 - \-> pos
\<< nb "." "" SREPL DROP DUP SIZE \-> nb1 sz1
\<< pos 2 / FP 0 ==
IF
THEN sz1 2 / FP 0 \=/
IF
THEN nb1 0 + 'nb1' STO
END
ELSE sz1 2 / FP 0 ==
IF
THEN nb1 0 + 'nb1' STO
END
END nb1
\>>
\>>
ELSE nb "." "" SREPL DROP
END
\>> DUP SIZE 2 / FP 0 == "" 0 IFTE SWAP + DUP SIZE 2 / \-> n sz
\<< { } 0 sz 1 -
FOR i n i 2 * 1 + DUP 1 + SUB OBJ\-> +
NEXT 'n' STO 0 0 0 0 1 \-> a b m s k
\<<
WHILE k digit <
REPEAT a b - 100 * 'a' STO k sz \<=
IF
THEN n k GET 'a' STO+
END 1 'k' STO+ 9 's' STO
WHILE 20 m * s + s * a >
REPEAT -1 's' STO+
END 20 m * s + s * 'b' STO 10 m * s + 'm' STO
END m \->STR \-> st
\<< st 2 50
FOR i st i digit 1 - SUB OBJ\-> 0 ==
IF
THEN 1 i 1 - SUB digit 1 - 'i' STO
END
NEXT OBJ\-> DUP2 ==
IF
THEN SWAP DROP
END
\>>
\>>
\>>
\>>
\>>
52.3 ASN
(Or 52.1 ASN or 52.2 ASN.)

We assign (ASN command) this program to the square root key 52.

Example 1
Introduce for instance 9
and LS User
Then sqrt-key (under the EVAL-key).
You get in level stack 2 sqrt(9)
3 in level stack 1

Example 2
Introduce now 9
and LS User
Then sqrt-key (under the EVAL-key).
You get in level stack 3 sqrt(900)
30 in level stack 2 (normally an approximation).
3, which represents the first "50 digits, less the redundant zeroes".

Example 3
Insure yourself that you are in exact mode.
Type 1234567891234
Then press ENTER
Then press a second time ENTER
Ptess * in order to multiply both identical numbers in the stack.
You should get 1524157878065965654042756
Now LS User
Then sqrt-key (under the EVAL-key).
You get in level stack 3
"Sqrt(1524157878065965654042756)"
In stack level 2 the approximative result 1.23456789124E12
And 1234567891234 in level 1 (the zeroes after the second digit 4 on the right are left out).

Example 4
Insure yourself that you are in exact mode.
Type as argument
1524157878065965654042757
(757 at the end, and not 756).
Now LS User
Then sqrt-key (under the EVAL-key).
You get in level stack 3
"Sqrt(1524157878065965654042756)"
In stack level 2 the approximative result 1.23456789124E12
And 1234567891234 in level 1 (the zeroes after the second digit 4 on the right are left out).

Example 4
Insure yourself that you are in exact mode.
Type as argument
1524157878065965654042757
(757 at the end, and not 756).
Now LS User
Then sqrt-key (under the EVAL-key).
You get in level stack 3
"Sqrt(1524157878065965654042757)"
In stack level 2 the approximative result 1.23456789124E12
And 12345678912340000000000004050000032806863265750682 in level 1. Note that, this time, the zeroes after the second digit 4 on the right do appear as, after them, do appear also different ≠0-digits.

Example 5
12.178 LS-User SQRT-Key
Gives
"sqrt(12.178) " in stack level 3
3.48969912743 in stack level 2
and, in stack level 1, 34896991274320484031821999216879351359311052016725

Example 6
Sqrt 1.2178
Gives, in stack level 3,"sqrt(1.2178)"
1.10353975914 in stack level 2
and, in stack level 1,
11035397591387453041375873710499307803985079728862.

Seems to work fine.

Best is to use the phone EMU48 application if you don't want to way too much for the answers.

Note that you can modify the number of digits to be calculated and shown.

Regards,
Gil Campart


Attached File(s)
.doc  ROOT2.V1.DOC (Size: 1.05 KB / Downloads: 1)
Find all posts by this user
Quote this message in a reply
04-27-2021, 05:30 PM
Post: #2
RE: HP49-50G Square root many (50 or more) digits
Version 2

You can keep the version 1.

For 50 digits, this new version instead going to a loop =
"51-1" and k<51,

has its loop that goes, more logically, directly up to the required digit 50 (not 51-1) and k<= 50 (not k<51).

The new code and in bold the changes
\<< "\[] 1 Arg

\[] Put below 100 if
you want 100 digits
" DROP 50 \-> digit
\<< -105 CF DUP "\v/" SWAP + SWAP DUP \v/ SWAP DUP \->STR SWAP FP \-> nb f
\<<
IF f 0 \=/
THEN nb "." POS 1 - \-> pos
\<< nb "." "" SREPL DROP DUP SIZE \-> nb1 sz1
\<< pos 2 / FP 0 ==
IF
THEN sz1 2 / FP 0 \=/
IF
THEN nb1 0 + 'nb1' STO
END
ELSE sz1 2 / FP 0 ==
IF
THEN nb1 0 + 'nb1' STO
END
END nb1
\>>
\>>
ELSE nb "." "" SREPL DROP
END
\>> DUP SIZE 2 / FP 0 == "" 0 IFTE SWAP + DUP SIZE 2 / \-> n sz
\<< { } 0 sz 1 -
FOR i n i 2 * 1 + DUP 1 + SUB OBJ\-> +
NEXT 'n' STO 0 0 0 0 1 \-> a b m s k
\<<
WHILE k digit \<=
REPEAT a b - 100 * 'a' STO k sz \<=
IF
THEN n k GET 'a' STO+
END 1 'k' STO+ 9 's' STO
WHILE 20 m * s + s * a >
REPEAT -1 's' STO+
END 20 m * s + s * 'b' STO 10 m * s + 'm' STO
END m \->STR \-> st
\<< st 2 50
FOR i st i digit SUB OBJ\-> 0 ==
IF
THEN 1 i 1 - SUB digit 'i' STO
END
NEXT OBJ\-> DUP2 ==
IF
THEN SWAP DROP
END
\>>
\>>
\>>
\>>
\>>

Then for assigning to sqrt-key write :
52.3 ASN ENTER.

Regards,
Gil


Attached File(s)
.doc  ROOT2.V2.DOC (Size: 1.04 KB / Downloads: 0)
Find all posts by this user
Quote this message in a reply
05-04-2021, 02:24 PM
Post: #3
RE: HP49-50G Square root many (50 or more) digits
RE: HP49-50G
Square root many (50 or more) digits
Version 3

Corrected / trapped some small errors.

Allows now to enter as argument

1) A positive/negative number like:
-4 (you will get a complex as an answer)
4.6
2.56E28
715.57E19

2) Or a string — for more or full precision when working with exponents (or with "," + many digits) — like:
"-4. 11111111234567888889067"
"4.62345778933456789"
"2.564546677890677E28"
"715.575675677889E19"

3 or 4 results

3 results:
- how many last digits of 50 (or of 100, depending on your settings) were calculated being = 0 and were cut in the final result;
(note that if no digit was cut in the result, then that first line information will not appear);
- the initial argument in a string with the sqrt sign;
- the exact or approximate result as calculated by the sqrt key function of the calculator.

4 results:
When the exact value is not possible with the normal sqrt function of the calculator, a last (fourth) line is added with all the significative digits ≠ 0 (in principle, 50 digits, but remember that when last digits calculated are = 0, the latter are not shown).

Here is the full, changed code:
\<< "\[] 1 Arg

\[] Put below 100 if
you want 100 digits
" DROP 50 \-> digit
\<< DUP TYPE 2 \=/
IF
THEN \->STR
END DUPDUP SIZE SWAP OBJ\-> \-> x0 s0 x1
\<< -3 SF -105 CF "\v/" x0 + x1 \v/ x0 "-" "" SREPL DROP 'x0' STO x0 DUP "E" POS DUP 0 ==
IF
THEN DROP 1 s0
ELSE 1 SWAP 1 -
END SUB "." "" SREPL DROP DUP SIZE 's0' STO 'x0' STO x1 MANT x1 XPON \-> man xpo
\<< s0 2 / FP 0 \=/
IF
THEN 0 x0 xpo 2 / FP 0 \=/ { SWAP } IFT +
ELSE xpo 2 / FP 0 ==
IF
THEN 0 x0 + 0 +
ELSE x0
END
END DUPDUP 'x0' STO SIZE 2 / \-> n sz
\<< { } 0 sz 1 -
FOR i n i 2 * 1 + DUP 1 + SUB OBJ\-> +
NEXT 'n' STO 0 0 0 0 1 \-> a b m s k
\<<
WHILE k digit \<=
REPEAT a b - 100 * 'a' STO k sz \<=
IF
THEN n k GET 'a' STO+
END 1 'k' STO+ 9 's' STO
WHILE 20 m * s + s * a >
REPEAT -1 's' STO+
END 20 m * s + s * 'b' STO 10 m * s + 'm' STO
END m \->STR \-> st
\<< st 2 digit
FOR i st i digit SUB OBJ\-> 0 ==
IF
THEN digit i - 1 + " last # of \v/ =0" + 4 ROLLD 1 i 1 - SUB digit 'i' STO
END
NEXT OBJ\-> DUP2 \-> r1 r2
\<< r1 DUP TYPE 1 ==
IF
THEN IM
END MANT \->STR "." "" SREPL DROP DUP "E" POS DUP 0 >
IF
THEN 1 - 1 SWAP SUB OBJ\->
ELSE DROP OBJ\->
END r2 ==
IF
THEN DROP
END
\>>
\>>
\>>
\>>
\>>
\>>
\>>
\>>
523 ASN

Regards,
Gil


Attached File(s)
.doc  ROOT2.V3.3.DOC (Size: 1.25 KB / Downloads: 0)
Find all posts by this user
Quote this message in a reply
05-04-2021, 08:19 PM
Post: #4
RE: HP49-50G Square root many (50 or more) digits
Just corrected the code
for cases of the type sqrt (2E-2).

Besides you can now choose how many digits you want to be calculated by using as input:
{X xx},
- where X is the number of which you want the square root
- and where cx is number of digits to be calculated.

By default, the number xx is 50.
In that case, you can directly enter as argument:
X or "XX" (double quotation mark).

The full, new code is:
\<< "Version 4

Give 1 Arg

\[] 2.5 or 2.5E6 or
-2.5 or 2.5-E6 or

\[] or" "1234567891234567" "with quotation mark!

\[] or {X xx}
with X: like above
& xx: # digits
" 3 DROPN DUP TYPE 5 ==
IF
THEN OBJ\-> DROP
ELSE 50 "Put above 100 if
you want 100 digits" DROP
END
\-> digit
\<< DUP TYPE 2 \=/
IF
THEN \->STR
END DUPDUP SIZE SWAP OBJ\-> \-> x0 s0 x1
\<< -3 SF -105 CF "\v/" x0 + x1 \v/ x0 "-" "" SREPL DROP 'x0' STO x0 DUP "E" POS DUP 0 ==
IF
THEN DROP 1 s0
ELSE 1 SWAP 1 -
END SUB "." "" SREPL DROP OBJ\-> \->STR DUP SIZE 's0' STO 'x0' STO x1 MANT x1 XPON \-> man xpo
\<< s0 2 / FP 0 \=/
IF
THEN 0 x0 xpo 2 / FP 0 \=/ { SWAP } IFT +
ELSE xpo 2 / FP 0 ==
IF
THEN 0 x0 + 0 +
ELSE x0
END
END DUPDUP 'x0' STO SIZE 2 / \-> n sz
\<< { } 0 sz 1 -
FOR i n i 2 * 1 + DUP 1 + SUB OBJ\-> +
NEXT 'n' STO 0 0 0 0 1 \-> a b m s k
\<<
WHILE k digit \<=
REPEAT a b - 100 * 'a' STO k sz \<=
IF
THEN n k GET 'a' STO+
END 1 'k' STO+ 9 's' STO
WHILE 20 m * s + s * a >
REPEAT -1 's' STO+
END 20 m * s + s * 'b' STO 10 m * s + 'm' STO
END m \->STR \-> st
\<< st 2 digit
FOR i st i digit SUB OBJ\-> 0 ==
IF
THEN digit i - 1 + " last # of \v/ =0" + 4 ROLLD 1 i 1 - SUB digit 'i' STO
END
NEXT OBJ\-> DUP2 \-> r1 r2
\<< r1 DUP TYPE 1 ==
IF
THEN IM
END MANT \->STR "." "" SREPL DROP DUP "E" POS DUP 0 >
IF
THEN 1 - 1 SWAP SUB OBJ\->
ELSE DROP OBJ\->
END r2 ==
IF
THEN DROP
END
\>>
\>>
\>>
\>>
\>>
\>>
\>>
\>>


Attached File(s)
.doc  ROOT2.V4.DOC (Size: 1.45 KB / Downloads: 0)
Find all posts by this user
Quote this message in a reply
Post Reply 




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