Post Reply 
mixed fraction program for hp 28s
10-10-2024, 07:46 PM
Post: #1
mixed fraction program for hp 28s
Hello,

i found this program some time ago that gives a mixed fraction on hp 28s. After keying in the program it returned a syntax error. does anyone know what might be wrong with it, or better, have a working program to share? here's the malfunctioning one i've tried:

"The following is the one that gives output like '3+4/5' for 3.8
<< -> a
<< a IP ->NUM ->STR
IF a ->NUM FP
THEN "+" + a FP FRAC O->S +
END S->N
>>
>>

cheers!
Find all posts by this user
Quote this message in a reply
10-10-2024, 08:15 PM
Post: #2
RE: mixed fraction program for hp 28s
I don't believe FRAC, O->S or S->N are valid commands.
Visit this user's website Find all posts by this user
Quote this message in a reply
10-11-2024, 08:44 AM
Post: #3
RE: mixed fraction program for hp 28s
Something like this?
Code:
DIR
  R\->N
    \<< \->NUM \-> a
      \<< a IP \->STR
        IF a FP
        THEN "+" + a FP FRAC O\->S +
        END S\->N
      \>>
    \>>
  FRAC
    \<< \-> a
      \<< (0,1) (1,1)
        WHILE DUP2 + DUP C\->R / DUP a \=/
        REPEAT
          IF a <
          THEN SWAP ROT
          ELSE SWAP
          END DROP
        END DROP ROT DROP SWAP DROP C\->R
      \>>
    \>>
  O\->S
    \<< "/" SWAP + +
    \>>
  S\->N
    \<< "'" SWAP OVER + + STR\->
    \>>
END

Examples

3.8
R→N

'3+4/5'

'π^2/6'
R→N

'1+727069/1127354'


Warning: Don't try negative numbers.
Find all posts by this user
Quote this message in a reply
10-11-2024, 09:10 AM
Post: #4
RE: mixed fraction program for hp 28s
Addendum: Just remembered this older thread: fraction program hp 28s?
It contains also a program FRAC but I haven't checked if this would work here.
Find all posts by this user
Quote this message in a reply
10-11-2024, 02:47 PM
Post: #5
RE: mixed fraction program for hp 28s
(10-10-2024 08:15 PM)Steve Simpkin Wrote:  I don't believe FRAC, O->S or S->N are valid commands.

i tried it without, the syntax error was gone but the program is still not working, when prompted it displays the entire program..
Find all posts by this user
Quote this message in a reply
10-11-2024, 02:51 PM
Post: #6
RE: mixed fraction program for hp 28s
(10-11-2024 08:44 AM)Thomas Klemm Wrote:  Something like this?
Code:
DIR
  R\->N
    \<< \->NUM \-> a
      \<< a IP \->STR
        IF a FP
        THEN "+" + a FP FRAC O\->S +
        END S\->N
      \>>
    \>>
  FRAC
    \<< \-> a
      \<< (0,1) (1,1)
        WHILE DUP2 + DUP C\->R / DUP a \=/
        REPEAT
          IF a <
          THEN SWAP ROT
          ELSE SWAP
          END DROP
        END DROP ROT DROP SWAP DROP C\->R
      \>>
    \>>
  O\->S
    \<< "/" SWAP + +
    \>>
  S\->N
    \<< "'" SWAP OVER + + STR\->
    \>>
END

Examples

3.8
R→N

'3+4/5'

'π^2/6'
R→N

'1+727069/1127354'


Warning: Don't try negative numbers.

i was getting syntax error and the cursor is placed at the parenthesis (1,1) i changed the commas in both parentheses to a point but then it returns a syntax error with cursor placed at the very end of the program..
is it working on your calculator?
Find all posts by this user
Quote this message in a reply
10-11-2024, 04:13 PM (This post was last modified: 10-11-2024 07:02 PM by Thomas Klemm.)
Post: #7
RE: mixed fraction program for hp 28s
(10-11-2024 02:51 PM)Rafa Wrote:  I was getting syntax error and the cursor is placed at the parenthesis (1,1)

You probably use a comma , instead of a period . as decimal point character.
Either use a semicolon ; or just a space between the numbers: (0 1) (1 1)

(10-11-2024 02:51 PM)Rafa Wrote:  is it working on your calculator?

It runs on an HP-48. I assumed it would run on an HP-28 too.
If complex numbers don't work, you could try using vectors instead: [0 1] [1 1]
And then use V→ instead of C→R to decompose them.
Find all posts by this user
Quote this message in a reply
10-11-2024, 06:35 PM (This post was last modified: 10-11-2024 07:06 PM by Gilles.)
Post: #8
RE: mixed fraction program for hp 28s
With my HP50g it could be :
Code:
R→N : « DUP IP OVER FP →Q + »

But perhaps →Q dont exists on the 28S ?
Why use string objects while algebraic objects does the job ?
Find all posts by this user
Quote this message in a reply
10-11-2024, 06:59 PM
Post: #9
RE: mixed fraction program for hp 28s
(10-11-2024 06:35 PM)Gilles Wrote:  With my HP50g it could be :
Code:
R→N « DUP IP OVER FP →Q + »

But perhaps →Q dont exists on the 28S ?
Why use string objects while algebraic objects does the job ?

Correct, →Q was not introduced until the HP-48SX.
Visit this user's website Find all posts by this user
Quote this message in a reply
10-11-2024, 07:15 PM (This post was last modified: 10-11-2024 07:18 PM by Thomas Klemm.)
Post: #10
RE: mixed fraction program for hp 28s
(10-11-2024 06:35 PM)Gilles Wrote:  With my HP50g it could be :
Code:
R→N « DUP IP OVER FP →Q + »

Interestingly your program gives a different answer:

'π^2/6'
→NUM
R→N

'1+78609550141/121887731137'

Both results evaluate to the same initial value:

1.64493406685

Thus I wonder which algorithm is used in →Q.
Find all posts by this user
Quote this message in a reply
10-11-2024, 07:33 PM (This post was last modified: 10-11-2024 07:35 PM by Gilles.)
Post: #11
RE: mixed fraction program for hp 28s
(10-11-2024 06:59 PM)Steve Simpkin Wrote:  Correct, →Q was not introduced until the HP-48SX.
So we could perhaps create this one with the FRAC below, the algebraic 'A/B' and the OBSUB command I see in the 28s reference manuel. Just an idea, i dont own a 28S and OBSUB dont exist in the 48SX and 50g si In can't test.
Find all posts by this user
Quote this message in a reply
10-11-2024, 07:58 PM (This post was last modified: 10-11-2024 08:13 PM by Gilles.)
Post: #12
RE: mixed fraction program for hp 28s
(10-11-2024 07:15 PM)Thomas Klemm Wrote:  Thus I wonder which algorithm is used in →Q.
I don't know the algorithm but the accuracy of →Q depends on the FIX parameter.
I was always impressed by its speed, even with my old 48SX. There is also a command →Qπ which allows to retrieve for example π/4 with the real value of ACOS (√2/2) in radians. And √2/2 →NUM →Qπ returns √(1/2) , then simplify returns √2/2

AUR says :
Quote:To Quotient Command: Returns a rational form of the argument.
The rational result is a “best guess”, since there might be more than one rational expression
consistent with the argument. →Q finds a quotient of integers that agrees with the argument to
within the number of decimal places specified by the display format mode.
→Q also acts on numbers that are part of algebraic expressions or equations

And for →Qπ
Quote:To Quotient Times π Command: Returns a rational form of the argument, or a rational form of
the argument with π, square roots, natural logs, and exponentials factored out, whichever yields
the smaller denominator.
The rational result is a “best guess”, since there might be more than one rational expression
consistent with the argument. →Qπ finds a quotient of integers that agrees with the argument to
the number of decimal places specified by the display format mode.
→Qπ also acts on numbers that are part of algebraic expressions or equations.
Find all posts by this user
Quote this message in a reply
10-11-2024, 08:10 PM
Post: #13
RE: mixed fraction program for hp 28s
(10-11-2024 06:35 PM)Gilles Wrote:  Why use string objects while algebraic objects does the job ?

The problem is that numbers can't be quoted.
This is the best I could come up with:

4 5
O→S

"4/5"

S→N

'4/5'


But I agree, from this point on the integer part could just be added.
Apart from a minor change I didn't bother to rewrite the main function but just added the missing ones to make it work.
Find all posts by this user
Quote this message in a reply
10-11-2024, 08:17 PM
Post: #14
RE: mixed fraction program for hp 28s
(10-11-2024 08:10 PM)Thomas Klemm Wrote:  
(10-11-2024 06:35 PM)Gilles Wrote:  Why use string objects while algebraic objects does the job ?

The problem is that numbers can't be quoted.
This is the best I could come up with:

4 5
O→S

"4/5"

S→N

'4/5'


But I agree, from this point on the integer part could just be added.
Apart from a minor change I didn't bother to rewrite the main function but just added the missing ones to make it work.

What about :
'A' 1 {123} OBSUB
does it returns '123' ?

or perhaps
'A' 1 123 OBSUB
Find all posts by this user
Quote this message in a reply
10-12-2024, 11:45 AM (This post was last modified: 10-12-2024 11:46 AM by John Keith.)
Post: #15
RE: mixed fraction program for hp 28s
(10-11-2024 06:35 PM)Gilles Wrote:  With my HP50g it could be :
Code:
R→N : « DUP IP OVER FP →Q + »

\->Q PROPFRAC is even shorter.
Find all posts by this user
Quote this message in a reply
10-13-2024, 06:56 PM
Post: #16
RE: mixed fraction program for hp 28s
(10-12-2024 11:45 AM)John Keith Wrote:  
(10-11-2024 06:35 PM)Gilles Wrote:  With my HP50g it could be :
Code:
R→N : « DUP IP OVER FP →Q + »

\->Q PROPFRAC is even shorter.

Big Grin One life is not enough to master all the subtleties of the 50g !
Find all posts by this user
Quote this message in a reply
Post Reply 




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