From c1131490d8282e8fe76ac348e3cf500598be2590 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 31 Aug 2008 14:37:53 +0200 Subject: MLKNumber: Add -numerator and -denominator. --- MLKNumber.h | 3 +++ MLKNumber.m | 12 ++++++++++++ MLKRatio.h | 4 ++-- MLKRatio.m | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/MLKNumber.h b/MLKNumber.h index e9c5843..f7b7e37 100644 --- a/MLKNumber.h +++ b/MLKNumber.h @@ -25,5 +25,8 @@ -(MLKNumber *) multiplyWith:(MLKNumber *)arg; -(MLKNumber *) divideBy:(MLKNumber *)arg; +-(MLKNumber *) numerator; +-(MLKNumber *) denominator; + -(double) doubleValue; @end diff --git a/MLKNumber.m b/MLKNumber.m index 680dfe7..5a0a527 100644 --- a/MLKNumber.m +++ b/MLKNumber.m @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#import "MLKInteger.h" #import "MLKNumber.h" #import @@ -36,5 +37,16 @@ DECLARE_ABSTRACT (-(MLKNumber *) subtract:(MLKNumber *)arg, nil) DECLARE_ABSTRACT (-(MLKNumber *) multiplyWith:(MLKNumber *)arg, nil) DECLARE_ABSTRACT (-(MLKNumber *) divideBy:(MLKNumber *)arg, nil) +-(MLKNumber *) numerator +{ + return self; +} + +-(MLKNumber *) denominator +{ + return [MLKInteger integerWithInt:1]; +} + DECLARE_ABSTRACT (-(double) doubleValue, 0.0) @end + diff --git a/MLKRatio.h b/MLKRatio.h index 69acbc1..394bc41 100644 --- a/MLKRatio.h +++ b/MLKRatio.h @@ -53,8 +53,8 @@ -(NSComparisonResult) compare:(MLKRatio *)arg; -(BOOL) isEqual:(id)arg; --(MLKInteger *) numerator; --(MLKInteger *) denominator; +-(MLKNumber *) numerator; +-(MLKNumber *) denominator; -(NSString *) description; -(NSString *) descriptionWithBase:(int)base; diff --git a/MLKRatio.m b/MLKRatio.m index 045e583..fa1e9df 100644 --- a/MLKRatio.m +++ b/MLKRatio.m @@ -89,7 +89,7 @@ DEFINE_MPQ_TWOARG_OPERATION (divideBy:, mpq_div) return mpq_get_d (value); } --(MLKInteger *) numerator +-(MLKNumber *) numerator { mpz_t numer; MLKInteger *obj; @@ -101,7 +101,7 @@ DEFINE_MPQ_TWOARG_OPERATION (divideBy:, mpq_div) return obj; } --(MLKInteger *) denominator +-(MLKNumber *) denominator { mpz_t denom; MLKInteger *obj; -- cgit v1.2.3