Post Reply 
(49G) Integer to Long Real Programme
05-21-2015, 08:27 PM (This post was last modified: 06-15-2017 01:45 PM by Gene.)
Post: #1
(49G) Integer to Long Real Programme
Some time ago I wrote a programme to convert zints to long reals. Looking at the programme again, I realised it was only good for values < 10^500. Here's the old programme:

OLDPROG

::
CK1&Dispatch
# FF
::
DUPDUP
CODE 00025 143174E78FB9760131174143818F858DC7530
DUP
BINT13
#<
case2drop
FPTR2 ^Z2%%
BINT12
#-
Z10_
SWAP
FPTR2 ^PPow#
FPTR2 ^ZMod
DUPUNROT
FPTR2 ^RSUBext
FPTR2 ^Z2%%
SWAP
FPTR2 ^Z2%%
%%+
;
;

And here's the new programme good for zints as large as you like.

If anyone else has done this please tell me - improvements most welcome.

NEWPROG

::
CK1&Dispatch
# FF
::
FPTR2 ^DupZIsNeg?
ITE
%% -1E0
%%1
SWAP
FPTR2 ^ZAbs
DUP
FPTR2 ^Z>S
DUPLEN$
DUP
BINT13
#<
case2drop
::
FPTR2 ^Z2%%
%%*
;
ROTDROP
OVER
BINT1
BINT12
SUB$
FPTR2 ^S>Z
FPTR2 ^Z>R
%MANTISSA
%>%%
ROT
BINT13
BINT16
SUB$
FPTR2 ^S>Z
FPTR2 ^Z2%%
%% 1E15
%%/
%%+
%%10
ROT
#1-
FPTR2 ^PPow#
%%*
%%*
;
;
Find all posts by this user
Quote this message in a reply
05-22-2015, 07:20 AM (This post was last modified: 05-22-2015 01:23 PM by Gerald H.)
Post: #2
RE: HP 49G: Integer to Long Real Programme
I'm sorry to say the above programme does not deal with numbers of the form 123456789012006 correctly, but just drops the bold zeros.

The programme below should correct that error.

::
CK1&Dispatch
# FF
::
::
FPTR2 ^DupZIsNeg?
SWAP
FPTR2 ^ZAbs
DUP
FPTR2 ^Z>S
DUPLEN$
#1-DUP
BINT12
#<
case2drop
FPTR2 ^Z2%%
ROTDROP
OVER
BINT13
1_#1-SUB$
FPTR2 ^S>Z
FPTR2 ^Z>R
%MANTISSA
%>%%
ROT
BINT13
BINT16
SUB$
CHR_.
>H$
palparse
DROP
%>%%
%% 1E11
%%/
%%+
%%10
ROT
FPTR2 ^PPow#
%%*
;
SWAP
NOT?SEMI
%%CHS
;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




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