summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Benkard <mulk@minimulk.mst-plus>2008-08-31 14:37:53 +0200
committerMatthias Benkard <mulk@minimulk.mst-plus>2008-08-31 14:40:59 +0200
commitc1131490d8282e8fe76ac348e3cf500598be2590 (patch)
treeff0df8b525b84d038fa115ce9b7aa626693ecc3e
parent7d8b67518c7572872da35cb2270419c04f0f19b1 (diff)
MLKNumber: Add -numerator and -denominator.
-rw-r--r--MLKNumber.h3
-rw-r--r--MLKNumber.m12
-rw-r--r--MLKRatio.h4
-rw-r--r--MLKRatio.m4
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
+
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;