(49G) Integer to Long Real Programme - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (49G) Integer to Long Real Programme (/thread-3939.html) |
(49G) Integer to Long Real Programme - Gerald H - 05-21-2015 08:27 PM 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# %%* %%* ; ; RE: HP 49G: Integer to Long Real Programme - Gerald H - 05-22-2015 07:20 AM 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 ; ; |