diff options
author | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-31 14:37:53 +0200 |
---|---|---|
committer | Matthias Benkard <mulk@minimulk.mst-plus> | 2008-08-31 14:40:59 +0200 |
commit | c1131490d8282e8fe76ac348e3cf500598be2590 (patch) | |
tree | ff0df8b525b84d038fa115ce9b7aa626693ecc3e | |
parent | 7d8b67518c7572872da35cb2270419c04f0f19b1 (diff) |
MLKNumber: Add -numerator and -denominator.
-rw-r--r-- | MLKNumber.h | 3 | ||||
-rw-r--r-- | MLKNumber.m | 12 | ||||
-rw-r--r-- | MLKRatio.h | 4 | ||||
-rw-r--r-- | 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 <http://www.gnu.org/licenses/>. */ +#import "MLKInteger.h" #import "MLKNumber.h" #import <Foundation/NSException.h> @@ -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 + @@ -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; @@ -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; |