The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
HP 49G: Challenge - Truncate a Long Real
07-06-2015, 07:49 PM
Post: #1
HP 49G: Challenge - Truncate a Long Real
Here is my attempt to truncate a long real imitating the real function TRNC.

For long real input

%% 5.12345678901
%% 5

the programme returns

%% 5.12345

& for input

%% 5.12345678901
%% -5

returns

%% 5.1234.

I find it hard to believe this is the most economical way to do it.

Can you suggest a less long-winded programme?

Code:

::
  CK2&Dispatch
  # 3F3F
  ::
    DUP%%0=_
    casedrop
    ::
      DUP
      ::
        DUP%%0=_
        ?SEMI
        DUP
        %%ABS
        %%/
      ;
      SWAP
      %%ABS
      %%INT
      %%*
    ;
    DUP
    %%ABS
    %%.5
    %%+
    %%INT
    SWAP
    ::
      DUP%%0=_
      ?SEMI
      DUP
      %%ABS
      %%/
    ;
    %%*
    DUP
    %%0>
    DUP
    4PICK
    DUP
    %%INT
    %%-
    %%0=
    AND
    case2DROP
    ?SKIP
    %%1+_
    %%ABS
    SWAPDUP
    %%ABS
    %%LN
    %%10
    %%LN
    %%/
    %%INT
    SWAP
    %%ABS
    %%10
    OVER
    %%ABS
    %%LN
    %%10
    %%LN
    %%/
    %%INT
    %%^
    %%/
    %%10
    4ROLL
    %%^
    %%*
    %%INT
    %%ABS
    %%10
    OVER
    %%ABS
    %%LN
    %%10
    %%LN
    %%/
    %%INT
    %%^
    %%/
    %%10
    ROT
    %%^
    %%*
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 49G: Challenge - Truncate a Long Real - Gerald H - 07-06-2015 07:49 PM



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