#!/bin/sh
#this is meant to be run in the directory containing an unmolested genius-0.4.3
# source distrbution. It adds modulo support for complex numbers.
# june 4, (c) 1999 jack schmidt <squeak@xirr.com> under the GPLv2.0
patch -d genius-0.4.3 -p1 << EOF
diff -U5 -ur genius-0.4.3/src/lexer.l genius-0.4.3.mod/src/lexer.l
--- genius-0.4.3/src/lexer.l	Mon May 24 21:20:45 1999
+++ genius-0.4.3.mod/src/lexer.l	Fri Jun  4 09:57:43 1999
@@ -208,10 +208,16 @@
 				/* identifier*/
 				yylval.id = g_strdup(yytext);
 				DO_RET;
 				return FUNCID;
 			}
+[0-9]+i		{
+			mpw_init(yylval.val);
+			mpw_set_str_complexint(yylval.val,yytext,0);
+			DO_RET;
+			return NUMBER;
+		}
 
 [0-9]*\.[0-9]+[e@]-?[0-9]+i	|
 [0-9]+[e@]-?[0-9]+i		|
 [0-9]+i				|
 [0-9]*\.[0-9]+i	{
diff -U5 -ur genius-0.4.3/src/mpwrap.c genius-0.4.3.mod/src/mpwrap.c
--- genius-0.4.3/src/mpwrap.c	Tue May 18 02:01:43 1999
+++ genius-0.4.3.mod/src/mpwrap.c	Fri Jun  4 09:55:56 1999
@@ -3608,22 +3608,33 @@
 }
 
 void
 mpw_mod(mpw_ptr rop,mpw_ptr op1, mpw_ptr op2)
 {
-	if(op1->type==MPW_REAL && op2->type==MPW_REAL) {
-		if(mpwl_sgn(op2->r)==0) {
-			(*errorout)(_("Division by zero!"));
-			error_num=NUMERICAL_MPW_ERROR;
-			return;
-		}
+	if((op2->type==MPW_REAL)&& (mpwl_sgn(op2->r)==0)) {
+		(*errorout)(_("Division by zero!"));
+		error_num=NUMERICAL_MPW_ERROR;
+	}
+	else if(op1->type==MPW_REAL && op2->type==MPW_REAL) {
 		MAKE_REAL(rop);
 		MAKE_COPY(rop->r);
 		mpwl_mod(rop->r,op1->r,op2->r);
+	} else if(op1->r->type<=MPW_INTEGER && op2->r->type<=MPW_INTEGER &&
+			op1->i->type<=MPW_INTEGER && op2->i->type<=MPW_INTEGER) {
+		mpw_t tmp1;
+		mpw_init(tmp1);
+		MAKE_COPY(rop->r);
+		MAKE_COPY(rop->i);
+		mpw_div(rop,op1,op2);
+		mpwl_round(rop->r);
+		mpwl_round(rop->i);
+		mpw_mul(tmp1,rop,op2);
+		mpw_sub(rop,op1,tmp1);
+		mpw_clear(tmp1);
 	} else {
+		(*errorout)(_("Won't do modulo with a float or a rational."));
 		error_num=NUMERICAL_MPW_ERROR;
-		(*errorout)(_("Can't modulo complex numbers"));
 	}
 }
 
 void
 mpw_gcd(mpw_ptr rop,mpw_ptr op1, mpw_ptr op2)
@@ -4206,10 +4217,30 @@
 mpw_set_str_int(mpw_ptr rop,char *s,int base)
 {
 	MAKE_REAL(rop);
 	MAKE_COPY(rop->r);
 	mpwl_set_str_int(rop->r,s,base);
+}
+
+void
+mpw_set_str_complexint(mpw_ptr rop,char *s,int base)
+{
+	char *p;
+	int size;
+
+	rop->type = MPW_COMPLEX;
+
+	p = g_strdup(s);
+	size = strlen(p);
+	if(p[size-1] == 'i')
+		p[size-1] = '\0';
+	MAKE_COPY(rop->i);
+	mpwl_set_str_int(rop->i,p,base);
+
+	g_free(p);
+
+	mpw_uncomplex(rop);
 }
 
 void
 mpw_set_str_complex(mpw_ptr rop,char *s,int base)
 {
diff -U5 -ur genius-0.4.3/src/mpwrap.h genius-0.4.3.mod/src/mpwrap.h
--- genius-0.4.3/src/mpwrap.h	Thu May  6 02:24:33 1999
+++ genius-0.4.3.mod/src/mpwrap.h	Fri Jun  4 08:51:34 1999
@@ -158,10 +158,11 @@
 
 void mpw_set_str_float(mpw_ptr rop,char *s,int base);
 
 /*reads only the imaginary part (use add for real part)*/
 void mpw_set_str_complex(mpw_ptr rop,char *s,int base);
+void mpw_set_str_complexint(mpw_ptr rop,char *s,int base);
 
 void mpw_set_str_int(mpw_ptr rop,char *s,int base);
 
 void mpw_set_str(mpw_ptr rop,char *s,int base);

EOF 
