summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKFloat.h18
-rw-r--r--MLKFloat.m26
2 files changed, 42 insertions, 2 deletions
diff --git a/MLKFloat.h b/MLKFloat.h
index fe9ed48..bd8c3e4 100644
--- a/MLKFloat.h
+++ b/MLKFloat.h
@@ -20,7 +20,12 @@
#import <Foundation/NSString.h>
-
+// An MLKFloat can represent any kind of CL floating-point number.
+//
+// MLKFloat itself is not instantiable. It is a class cluster whose
+// instances are of one of its subclasses (currently MLKSingleFloat und
+// MLKDoubleFloat; an arbitrary-precision, GMP-backed type is planned
+// for the future).
@interface MLKFloat : MLKLispValue
+(MLKFloat *) floatWithExponentMarker:(unichar)exponentMarker
integerPart:(NSString *)intPart
@@ -28,4 +33,15 @@
fractionalPart:(NSString *)fractPart
exponent:(NSString *)exponent
exponentNegative:(BOOL)exponentNegative;
+
+// Abstract methods.
+-(float) floatValue;
+-(double) doubleValue;
+
+-(MLKFloat *) add:(MLKFloat *)arg;
+-(MLKFloat *) subtract:(MLKFloat *)arg;
+-(MLKFloat *) multiplyWith:(MLKFloat *)arg;
+-(MLKFloat *) divideBy:(MLKFloat *)arg;
+
+-(NSString *) description;
@end
diff --git a/MLKFloat.m b/MLKFloat.m
index 4083146..4fc2144 100644
--- a/MLKFloat.m
+++ b/MLKFloat.m
@@ -21,6 +21,7 @@
#import "MLKDoubleFloat.h"
#import "MLKPackage.h"
#import "MLKDynamicContext.h"
+#import "MLKError.h"
@implementation MLKFloat : MLKLispValue
@@ -32,9 +33,13 @@
exponentNegative:(BOOL)exponentNegative
{
MLKSymbol *defaultFormat;
- MLKPackage *cl = [MLKPackage findPackage:@"COMMON-LISP"];
+ MLKPackage *cl;
+
+ cl = [MLKPackage findPackage:@"COMMON-LISP"];
defaultFormat = [[MLKDynamicContext currentContext]
valueForBinding:[cl intern:@"*READ-DEFAULT-FLOAT-FORMAT*"]];
+
+ // FIXME: Shouldn't the readtable decide which exponent markers do what?
if (exponentMarker == 'd' || exponentMarker == 'D'
|| exponentMarker == 'l' || exponentMarker == 'L'
|| ((exponentMarker == 'e' || exponentMarker == 'E')
@@ -52,4 +57,23 @@
exponent:exponent
exponentNegative:exponentNegative];
}
+
+#define DECLARE_ABSTRACT(SIGNATURE, RETURN_VALUE) \
+ SIGNATURE \
+ { \
+ [[MLKError errorWithMessage:@"Tried to invoke an abstract method."] raise]; \
+ return RETURN_VALUE; \
+ }
+
+DECLARE_ABSTRACT (-(float) floatValue, 0.0)
+DECLARE_ABSTRACT (-(double) doubleValue, 0.0)
+DECLARE_ABSTRACT (-(MLKFloat *) add:(MLKFloat *)arg, nil)
+DECLARE_ABSTRACT (-(MLKFloat *) subtract:(MLKFloat *)arg, nil)
+DECLARE_ABSTRACT (-(MLKFloat *) multiplyWith:(MLKFloat *)arg, nil)
+DECLARE_ABSTRACT (-(MLKFloat *) divideBy:(MLKFloat *)arg, nil)
+
+-(NSString *) description
+{
+ return [super description];
+}
@end