Post Reply 
Sharp PC-1500A Compiler
Yesterday, 03:09 AM
Post: #10
RE: Sharp PC-1500A Compiler
(12-02-2024 11:49 PM)toml_12953 Wrote:  It chokes on the Python function sqrt! Calculators have a square root function, no?

Python doesn't provide a sqrt function. It has to be imported from a library.

From Help & User Guide:
Quote:What is not supported
And won’t be
  • Imports and libraries

From List of HP42S Commands Reference:
\(
\begin{array}{|c|c|}
\hline
\text{HP42S Command} & \text{Supported in Python to RPN} & \text{Comments Parameters} & \text{Description (original HP42S)} \\
\hline
\text{SQRT} & \text{✓} & \text{(n)} & \text{Square root. Returns √x.} \\
\hline
\end{array}
\)

The following Python program works:
Code:
def radius(x, y):
    return SQRT(x**2 + y**2)

The generated code for the HP-42S can be optimized to:
Code:
LBL "radius"
STO 01          // param: y
RDN
STO 00          // param: x
RDN
RCL 00          // x
X↑2
RCL 01          // y
X↑2
+
SQRT            // Square root. Returns √x.
RTN             // return

You could also use the built-in function →POL instead:
Code:
r, phi = toPol(x, y)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Sharp PC-1500A Compiler - Josef - 11-21-2024, 06:05 AM
RE: Sharp PC-1500A Compiler - Jeff_Birt - 11-21-2024, 03:34 PM
RE: Sharp PC-1500A Compiler - Josef - 11-22-2024, 05:49 AM
RE: Sharp PC-1500A Compiler - Josef - 11-27-2024, 08:25 PM
RE: Sharp PC-1500A Compiler - Josef - 11-30-2024, 06:31 PM
RE: Sharp PC-1500A Compiler - Josef - Yesterday, 07:45 PM
RE: Sharp PC-1500A Compiler - Josef - 12-01-2024, 12:32 PM
RE: Sharp PC-1500A Compiler - Thomas Klemm - 12-02-2024, 08:41 PM
RE: Sharp PC-1500A Compiler - toml_12953 - 12-02-2024, 11:49 PM
RE: Sharp PC-1500A Compiler - Josef - 12-02-2024, 10:35 PM
RE: Sharp PC-1500A Compiler - Thomas Klemm - Yesterday 03:09 AM
RE: Sharp PC-1500A Compiler - toml_12953 - Yesterday, 03:41 AM
RE: Sharp PC-1500A Compiler - Josef - Yesterday, 08:00 PM



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