Post Reply 
HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
09-27-2017, 11:53 AM (This post was last modified: 09-28-2017 05:36 AM by Gerald H.)
Post: #11
RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge
Bravo Werner! I consider your contribution a complete solution & don't expect a shorter version (although "6 - 6 -" is ornate), would however be very pleased to see a more concise programme.

To keep my word & amuse Joe here's my version:

Edit: Corrected my programme to give correct result for zero. I have learned much from this thread, eg that .000000000001 is not the nearest representable number to zero.
I doubt that, given Werner's programme, anyone will now try this programme but the wrong result irritated me.

Code:
::
  CK1&Dispatch
  # FF
  ::
    Z1_
    FPTR2 ^RADDext
    DUP
    Z2_
    FPTR2 ^RSUBext
  ;
  BINT1
  ::
    DUP%0=
    casedrop
    ::
      %MINREAL
      DUP
      %CHS
    ;
    DUP
    %SGN
    SWAP
    ::
      %ABS
      DUP
      %>%%
      DO>STR
      DUP
      "E"
      BINT1
      POSCHR
      DUPUNROT
      2DUP
      LAST$
      3UNROLL
      1_#1-SUB$
      DUPLEN$
      ::
        #1=case
        ::
          ".00000000001"
          &$
          SWAP&$
          DOSTR>
          SWAPDROP
        ;
        ROTDUP
        BINT14
        #<>
        ITE
        ::
          BINT14
          SWAP#-
          ZERO_DO
          CHR_0
          >T$
          LOOP
        ;
        DROP
        CHR_6
        >T$
        SWAP&$
        DOSTR>
      ;
      DUPDUP
      4ROLL
      DUP
      %MANTISSA
      %1
      %=
      case
      ::
        2%>%%
        %%-
        DUP
        %%10
        %%/
        %%+
        SWAP
        %>%%
        SWAP
        %%-
        %%>%
      ;
      %-
      %2
      %*
      %-
    ;
    ROT
    %0>
    ?SEMI
    %CHS
    SWAP
    %CHS
  ;
;

Which does have the advantage of giving no wrong answers, ie for input

9.99999999999E499
1

Joe's returns

9.99999999999E499

& for

9.99999999999E499
9.99999999999E499

Werner's returns

9.99999999999E499

while for

9.99999999999E499

my programme errors.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 50g: Neighbour Function (Dedekind Cut) Programme Challenge - Gerald H - 09-27-2017 11:53 AM



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