Hy everybody,
below is my version, I copied the argument inside isEqualTo method, and I thought about a problem: if you don't declare the category where you are going to use it, it doesn't give an error when its already present in a parent class! for example isEqualTo already exists in NSObject! maybe it's superfluous but in my previous version I forgot to declare the category in main so I was using NSObject's method...

Fraction+Comparison.h
#import "Fraction.h"
#import "Fraction+MathOps.h"
@interface Fraction (Comparison)
-(BOOL) isEqualTo: (Fraction *) f;
-(int) compare: (Fraction *) f;
@end
Fraction+Comparison.m
Fraction *newF;
-(BOOL) isEqualTo: (Fraction *) f
{//copying argument to avoid changing its original value
{if (!newF)
newF = [[Fraction alloc] init];
newF.numerator=f.numerator;
newF.denominator=f.denominator;
}
[self reduce];
[newF reduce];
if ([self numerator] == [newF numerator] &&
[self denominator] == [newF denominator])
return YES;
else return NO;
}
-(int) compare: (Fraction *) f
{
newF = [self sub: f];
if((newF.numerator <0) || (newF.denominator<0) )
return -1;
else if(newF.numerator ==0)
return 0;
else if((newF.numerator >0) && (newF.denominator>0))
return 1;
else return 999;
}
@end
main.m
#import "Fraction.h"
#import "Complex.h"
#import "Fraction+MathOps.h"
#import "Fraction+Comparison.h"
int main (int argc, char *argv[])
{
//id c1 = [[Complex alloc] init];
Fraction *a = [[Fraction alloc] init];
Fraction *b = [[Fraction alloc] init];
Fraction *result;
[a setTo: 1 over: 4]; [b setTo: 1 over: 2];
[a printH];
[a print];
NSLog (@" +");
[b print];
NSLog (@"-----");
result = [a add: b];
[result print];
NSLog (@"\n");
[a print];
NSLog (@" -");
[b print];
NSLog (@"-----");
result = [a sub: b];
[result print];
NSLog (@"\n");
[a print]; NSLog (@" *"); [b print]; NSLog (@"-----"); result = [a mul: b];
[result print];
NSLog (@"\n");
[a print]; NSLog (@" /"); [b print]; NSLog (@"-----"); result = [a div: b];
[result print];
NSLog (@"\n");
NSLog(@"L'inverso di quest'ultima frazione è ");
[[result invert] print];
if ([a respondsToSelector: @selector (printH)] == YES)
{
NSLog(@"conforme ");
}
if ([a isEqualTo: b])
{
NSLog(@"Le due frazioni ");
[a print];
NSLog(@"e");
[b print];
NSLog(@"sono uguali" );
}
[a setTo: 1 over: 8]; [b setTo: 1 over: 4];
NSLog(@"Il confronto ritorna %i", [a compare: b]);
return 0;
}