Post Reply 
(12C) Decimal to Fraction
08-09-2018, 01:57 AM
Post: #25
RE: (12C) Decimal to Fraction
This program for the HP-11C includes Dieter's and Albert's suggestions:
Code:
  *LBL A        ; c f
   STO 1        ; c f
   CLx          ; 0 f
   STO 2        ; u=0 f
   R↓           ; f
   STO 0        ; f
   1            ; 1 f
   STO 3        ; v=1 f
  *LBL 0        ; while
   R↓           ; f
   x=0          ; f = 0 ?
   GTO 1        ; done
   1/x          ; 1/f
   FRAC         ; f'=frac(1/f)
   RCL 2        ; u f'
   LSTx         ; 1/f u f'
   INT          ; ⌊1/f⌋ u f'
   RCL 3        ; v ⌊1/f⌋ u f'
   STO 2        ; u'=v
   ×            ; v*⌊1/f⌋ u f'
   x<>y         ; u v*⌊1/f⌋ f'
   +            ; v'=u+v*⌊1/f⌋ f'
   RCL 1        ; c v' f'
   x≤y          ; c ≤ v' ?
   GTO 1        ; done
   R↓           ; v' f'
   STO 3        ; v' f'
   GTO 0        ; while
  *LBL 1        ; done
   LSTx         ; u c
   STO 2        ; u c
   -            ; c-u
   RCL 3        ; v c-v
   ÷            ; (c-u)/v
   INT          ; ⌊(c-u)/v⌋
   RCL 3        ; v ⌊(c-u)/v⌋
   ×            ; v*⌊(c-u)/v⌋
   STO + 2      ; u += v*⌊(c-u)/v⌋
   RCL 2        ; u
   GSB 4        ; diff
   RCL 3        ; v
   GSB 4        ; diff
   x≤y
   GTO 2
   RCL 2        ; u
   GTO 3
  *LBL 2
   RCL 3        ; v
  *LBL 3        ; round
   ENTER        ; d d
   ENTER        ; d d d
   RCL 0        ; f d d
   ×            ; f*d d
   .            ;
   5            ; 0.5 f*d d
   +            ; f*d+0.5 d
   INT          ; round(f*d) d
   RTN          ; n d
  *LBL 4        ; diff
   GSB 3        ; n d
   x<>y         ; d n
   ÷            ; n/d
   RCL 0        ; f n/d
   -            ; n/d-f
   ABS          ; |n/d-f|
   RTN          ; diff
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Decimal to Fraction - Gamo - 08-06-2018, 12:33 PM
RE: (12C) Decimal to Fraction - Dieter - 08-06-2018, 08:44 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:29 AM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 01:02 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 11:38 AM
RE: (12C) Decimal to Fraction - Gamo - 08-07-2018, 09:29 AM
RE: (12C) Decimal to Fraction - Joe Horn - 08-07-2018, 06:28 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:10 PM
RE: (12C) Decimal to Fraction - Joe Horn - 08-08-2018, 12:28 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 07:04 PM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 09:27 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 09:44 PM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 12:51 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 07:46 AM
RE: (12C) Decimal to Fraction - Thomas Klemm - 08-09-2018 01:57 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 08:09 AM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 09:16 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 10:30 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 12:28 PM
RE: (12C) Decimal to Fraction - Gamo - 05-07-2019, 01:44 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 07:06 PM



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