It is currently Wed Jun 03, 2020 3:26 am

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Adding and subtracting fractions?Posted: Mon Feb 17, 2014 6:27 pm

Joined: Mon Feb 17, 2014 6:20 pm
Posts: 2
So I have

DIVU #4, D2
DIVU #10, D3
DIVU #100, D4

to get 25%, 10%, and 1% of those registers but i have to sum them together and if I have a random initial value of \$00005000 in all of the registers I end up with a fraction in D3 and D4 and I'm unsure of how to add them together. Then subtract the sum of the 3 fractions from the initial value.

Top

 Post subject: Re: Adding and subtracting fractions?Posted: Wed Feb 19, 2014 11:04 am

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
I find your question to be unclear. Perhaps you could just quote the original homework assignment?

If you really need to add fractions on a 68000 (without floating point), you'll probably want to use scaled values. Googling "scaled integer arithmetic" might be a good place to start. Another possibility is rational arithmetic, but that's not what it sounds like you're describing.

Top

 Post subject: Re: Adding and subtracting fractions?Posted: Wed Feb 19, 2014 6:02 pm

Joined: Mon Feb 17, 2014 6:20 pm
Posts: 2
Ok so, Suppose there is already an initial value value in D1, I had to take 25% of D1 to put into D2, 10% into D3, and 1% into D4, Then in D5, it is the initial value - the sum of the %s.
I just rounded by dropping off the remainders. Just wondering if there was a better way to do it.

Top

 Post subject: Re: Adding and subtracting fractions?Posted: Thu Feb 20, 2014 1:04 pm

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
Invoke wrote:
Ok so, Suppose there is already an initial value value in D1, I had to take 25% of D1 to put into D2, 10% into D3, and 1% into D4, Then in D5, it is the initial value - the sum of the %s.
I just rounded by dropping off the remainders. Just wondering if there was a better way to do it.

I think what you're saying is that D2, D3, and D4 each hold a number that is a integer fraction of D1, not that they are fractions (have a part that's less than one). Is that right?

You're still paraphrasing the assignment instead of quoting it. I'm still confused as to what you want to do with the contents of D2..D4. Is D5 their sum? If so, it will not be the initial value (D1); 25%+10%+1% is not 100%. You also mentioned subtracting. Where does the result of that go? I think you need to post the code you've written so far.

As far as a "better way", it depends on what you're trying to accomplish, which is still unclear. Did you check the subjects I mentioned before?

Last edited by gtippery on Fri Apr 04, 2014 5:19 am, edited 1 time in total.

Top

 Post subject: Re: Adding and subtracting fractions?Posted: Thu Apr 03, 2014 7:36 pm

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
He's attempting to compute 36% of the original number, in order to then compute 64%

a = \$5000

p25 = (a / 4)
p10 = (a / 10)
p1 = (a / 100)
p36 = p25 + p10 + p1
p64 = a - p36

Which of course could also be done as

p64 = (a * 100) / 64

Top

 Post subject: Re: Adding and subtracting fractions?Posted: Fri Apr 04, 2014 5:23 am

Joined: Tue Nov 15, 2005 7:58 am
Posts: 129
Location: Oregon, USA
clive wrote:
He's attempting to compute 36% of the original number, in order to then compute 64%

a = \$5000

p25 = (a / 4)
p10 = (a / 10)
p1 = (a / 100)
p36 = p25 + p10 + p1
p64 = a - p36

Which of course could also be done as

p64 = (a * 100) / 64

Beats me how you figured this out, unless you've seen the assignment. If you have, is the 100%-(25%+10%+1%) method part of the assignment?

It'd still be good for him to post his code...

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 11 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects