Post Reply 
Getting 'N/D' to eval as a fraction not a decimal
03-10-2015, 04:24 AM
Post: #9
RE: Getting 'N/D' to eval as a fraction not a decimal
(03-09-2015 10:21 PM)BruceH Wrote:  Can you give some examples of numbers that fail? I'd like to turn this into an article.

There are several failures going on here, so here's a description of them all.

If N=23 and D=45, then all of the following (copied from the above discussion) return 0.51111111111 in Home instead of 23/45 *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:


If N=1234567, and D=3456789, then the following returns the wrong fraction in Home if epsilon (CAS Settings, page 2) is the default value (1E-12):

exact(N/D) --> 176366/493825 (should be 1234567/3456789)

The above can be "fixed" by making epsilon smaller (e.g. 1E-13 in this case), but then larger values of N and D will fail. For example, exact(12345678/23456789) is wrong when epsilon is 1E-13. Due to a very unfortunate CAS limitation, values of epsilon smaller than 1E-15 are all treated as 1E-15 by the "exact" function, so exact(N/D) is usually wrong when N and D are very large. For example, exact(12345678/23456789) is wrong no matter what epsilon is, even 1E-15 or smaller.

The solution to the original problem is to use functions that force the inputs (N and D) to be CAS-type integers, regardless of any mode settings. There are several functions that do this, such as IP. That's why CAS(IP(N)/IP(D)) works; the IP's turn the Home values of N and D into CAS-type integers, then CAS divides them and returns the fraction back to Home.

Annoying factoid: In CAS (not in Home), if the "Change apparent integer" flag is clear, then the IP function only turns the number into an integer if it's spelled in uppercase. Luckily, CAS(IP()) always sends IP to CAS in uppercase, no matter how the user spells it, so CAS(ip()) works in Home, and no matter what the CAS settings are. But CAS("ip(N)/ip(D)") fails, because "ip" got passed to CAS as-is (because it's in a string), and didn't get upper-cased.

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-10-2015 04:24 AM

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