Post Reply 
Getting 'N/D' to eval as a fraction not a decimal
03-07-2015, 01:48 AM (This post was last modified: 03-07-2015 02:02 AM by Joe Horn.)
Post: #4
RE: Getting 'N/D' to eval as a fraction not a decimal
(03-06-2015 08:32 PM)BruceH Wrote:  Well, I found a solution that (I think) always works, but it sure ain't elegant!

subst(N/D,N=N,D=D); gives '1/2'

Unfortunately that returns a single decimal fraction (not a ratio of two integers) if the non-programmable "Change apparent integers into exact integers" setting in CAS Settings (page 1, check box at end of line 3) is unchecked. Sad

EDIT: Very non-elegant, but this works:

print(string(N)+"/"+string(D))

EDIT 2: Do NOT use the following method unless both N and D are always very small integers. If either N or D are large, it is prone to error, and it depends on the value of the system variable epsilon (CAS Settings, page 2):

print(exact(N/D))

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Getting 'N/D' to eval as a fraction not a decimal - Joe Horn - 03-07-2015 01:48 AM



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