Amazon.com Widgets Does it or doesn't it? Ex 7.4
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 04:47:10 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 7
| | | |-+  Does it or doesn't it? Ex 7.4
Pages: [1]   Go Down
Print
Author Topic: Does it or doesn't it? Ex 7.4  (Read 974 times)
MarkReid
Full Member
***
Posts: 173






« on: March 19, 2010, 04:25:34 PM »

Can someone explain to me why or why wouldn't the Fraction class I've written work with negative fractions?

I feel that this is as much knowing the math of how negative fractions are calculated as much as anything else and unfortunately I don't have much of a clue.

I wrote a test program and it seems to work with negative fractions that I've tried but again I don't know the math behind it to really know so it's all rather confusing.

Many thanks.
Logged
pierre
Newbie
*
Posts: 32


Email




« Reply #1 on: March 19, 2010, 08:33:19 PM »

I post a message in the Chapter 11 folder "A bug in some solutions of exercises 11.2 and 11.3" that may answer your question.
Logged
MarkReid
Full Member
***
Posts: 173






« Reply #2 on: March 20, 2010, 03:50:32 PM »

Thanks for referring me to the post. I still don't really get the math aspect of it all the same.  Huh

Anyone else care to give describing it a shot or indeed if you want to take another try at it please?
Logged
JasonWitz
Newbie
*
Posts: 4


Email




« Reply #3 on: March 28, 2010, 10:53:07 PM »

I don't know if they question is really "does it work", i think it's more like, "does it display correctly".   Depending on what the sign was it could screw up the way it is displayed.  For example:

1/2 / -3/4 = 4/-6 without any sign checking.  You would not want to display a fraction like this.  You would want:
1/2 / -3/4 = -4/6.

The reduction method also seemed to mess with the sign although I can't give you a case off the top of my head.  I implemented a method to check the sign and fix it if necessary.  It looks like this:
Code: (Objective-C)
-(void) checkSign {
if ( denominator < 0  && numerator > 0) {
denominator *= -1;
numerator *= -1;
}
if (denominator < 0 && numerator < 0 ) {
denominator *= -1;
numerator *= -1;
}
}


Jason
Logged
MarkReid
Full Member
***
Posts: 173






« Reply #4 on: March 29, 2010, 02:29:18 AM »

Thanks Jason.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.