Re: Your "R->P" on HP-48G Message #13 Posted by James M. Prange (Michigan) on 13 Jan 2007, 9:08 p.m., in response to message #12 by Jeff O.
Actually, I rather prefer the way the 48/49 series handles this.
Complex numbers and vectors are always stored (as single objects)
in rectangular coordinates. How they're displayed (or decompiled
for editing or transfer) depends on the coordinate display mode,
which can be selected by the RECT, CYLIN, and SPHERE commands, and
of course on the angular display mode, which can be set by the
DEG, RAD, and GRAD commands.
You could also change the display modes using the system flags:
Flag -15 Set: Spherical (if flag -16 set)
Flag -15 Clear: Cylindrical (if flag -16 set)
Flag -16 Set: Cylindrical or spherical
Flag -16 Clear: Rectangular
Flag -17 Set: Radians
Flag -17 Clear: Degrees or Grads
Flag -18 Set: Grads (if flag -17 clear)
Flag -18 Clear: Degrees (if flag -17 clear)
To decompose to separate real numbers in rectangular coordinates,
you can use the OBJ\-> command, or to decompose to real numbers in
the current angular and coordinate display mode, use the V\->
command. To combine 2 (or 3) reals into a vector, use the \->V2
(or \->V3) command.
If flag -19 is set, then \->V2 makes a complex number, and if flag
-19 is clear, then \->V2 makes a vector.
You can also use the ARRY\-> and \->ARRY commands to convert
between vectors and reals, or the C\->R and R\->C commands to
convert between complex and real numbers.
The RE command give you the real part of a complex number, and the
IM command gives you the imaginary part of a complex number. ARG
gives you the polar angle of a complex number.
ABS gives you the "length" of a complex or array, that is, the
square root of the sum of the squares of its (rectangular)
components.
If you want the compiler to recognize that a real represents an
angular component of a vector, then prefix it with the "angle
symbol", invoked by ALPHA RightShift 6 on the 49 series, or
RightShift SPC on the 48 series. Note that converting it from
polar to rectangular coordinates for internal representation may
introduce a round-off error.
Also note that editing (or transferring) a vector when in
cylindrical or spherical coordinate display mode may also change
it slightly due to rounding off.
But here are the relevant entry points for the 49 series:
30E79 %REC>%POL ( %x %y -> %r %ang )
30EA6 %POL>%REC ( %r %ang -> %x %y )
30EDD %SPH>%REC ( %r %ang %ph -> %x %y %z )
Or for the 48 series:
2B48E %REC>%POL ( %x %y -> %r %ang )
2B4BB %POL>%REC ( %r %ang -> %x %y )
2B4F2 %SPH>%REC ( %r %ang %ph -> %x %y %z )
In SysRPL, "%" signs generally mean "real" numbers, and of course
the entry points are in hex notation, so for an R->P command, 2
real numbers are required for arguments, and the SYSEVAL sequence
for the 49 series would be:
#30E79h SYSEVAL
For the 49 series, the calculators have an MASD SysRPL/Assembly
compiler/decompiler built-in. Ordinarily, this is used with an
extable library so that named mnemonics can be used, but even
without extable, you can still use numeric entry points.
Source code for some 49 series SysRPL programs, with argument
checking:
%%HP: ; @ ASCII transfer header
@ R\->P, with extable:
"!NO CODE
!RPL
:: (Begin secondary)
CK2NOLASTWD (2 arguments required)
CK&DISPATCH1 (Strips tags and convert zints to reals, if needed)
2REAL (2 reals?)
%REC>%POL (convert)
; (End secondary)
@"
%%HP: ; @ ASCII transfer header
@ R\->P, without extable:
"!NO CODE
!RPL
::
PTR 2629C (CK2NOLASTWD)
PTR 26328 (CK&DISPATCH1)
# 11 (2REAL)
PTR 30E79 (%REC>%POL)
;
@"
%%HP: ; @ ASCII transfer header
@ P\->R, with extable:
"!NO CODE
!RPL
:: (Begin secondary)
CK2NOLASTWD (2 arguments required)
CK&DISPATCH1 (Strips tags and convert zints to reals, if needed)
2REAL (2 reals?)
%POL>%REC (convert)
; (End secondary)
@"
%%HP: ; @ ASCII transfer header
@ P\->R, without extable:
"!NO CODE
!RPL
::
PTR 2629C (CK2NOLASTWD)
PTR 26328 (CK&DISPATCH1)
# 11 (2REAL)
PTR 30EA6 (%POL>%REC)
;
@"
%%HP: ; @ ASCII transfer header
@ S\->R, with extable:
"!NO CODE
!RPL
:: (Begin secondary)
CK3NOLASTWD (3 arguments required)
CK&DISPATCH1 (Strips tags and convert zints to reals, if needed)
# 111 (3 reals?)
%SPH>%REC (convert)
; (End secondary)
@"
%%HP: ; @ ASCII transfer header
@ S\->R, without extable:
"!NO CODE
!RPL
::
PTR 262A1 (CK3NOLASTWD)
PTR 26328 (CK&DISPATCH1)
# 111
PTR 30EDD (%SPH>%REC)
;
@"
You can copy and paste the source code (beginning with the
"%%HP: ;" ASCII transfer headers) to files, and transfer them to a
49 series.
To compile the above source code with extable installed, put the
string on the stack and execute ASM; to decompile a SysRPL program
to a string, put the program on the stack and execute \->S2.
To do it without extable, you'll have to use one of the strings
without mnemonics. Assuming that the development library (256)
(which installing extable automatically attaches) isn't attached,
execute 256.06 MENU, and then press the ASM menu key.
The !NO CODE and !RPL lines are compiler directives. If you set
flag -92 (MASD SysRPL mode), then they can be omitted.
If you set flag -85 (SysRPL stk disp), then the programs (and
everything else) are displayed on the stack (but not in the
command line editor) in SysRPL mode.
Note that MASD requires the "@" to be the only character in the
last line of the string.
I'd encourage anyone interested to see
Programming
in System RPL Second Edition
For the 48 series, you'd have to use a different compiler. Maybe try a
search at http://www.hpcalc.org/, but
Debug4x should be a good
PC-based compiler for any 48/49 series.
A useful cross-reference of 48 and 49 series entry points can be
found at http://www.hpcalc.org/details.php?id=3248
The official HP extable library for the 49 series can be found at
http://www.hpcalc.org/details.php?id=3245, or extable2 (also
includes "unsupported but stable" entry points) can be found at
http://staff.science.uva.nl/~dominik/hpcalc/
Regards, James
Edited: 14 Jan 2007, 12:16 a.m.
|