27 |
|
|
28 |
#include "num_include.h" |
#include "num_include.h" |
29 |
|
|
30 |
object fixnum_add(i,j) |
object fixnum_add(int i, int j) |
|
int i,j; |
|
31 |
{ |
{ |
32 |
|
|
33 |
if (i>=0) |
if (i>=0) |
43 |
} |
} |
44 |
} |
} |
45 |
/* return i - j */ |
/* return i - j */ |
46 |
object fixnum_sub(i,j) |
object fixnum_sub(int i, int j) |
|
int i,j; |
|
47 |
{ |
{ |
48 |
|
|
49 |
if (i>=0) |
if (i>=0) |
60 |
} |
} |
61 |
|
|
62 |
object |
object |
63 |
fixnum_times(i, j) |
fixnum_times(int i, int j) |
|
int i, j; |
|
64 |
{ |
{ |
65 |
|
|
66 |
MPOP(return,mulss,i,j); |
MPOP(return,mulss,i,j); |
67 |
} |
} |
68 |
|
|
69 |
object |
object |
70 |
number_to_complex(x) |
number_to_complex(object x) |
|
object x; |
|
71 |
{ |
{ |
72 |
object z; |
object z; |
73 |
|
|
88 |
|
|
89 |
default: |
default: |
90 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
91 |
|
return(Cnil); |
92 |
} |
} |
93 |
} |
} |
94 |
|
|
95 |
object |
object |
96 |
number_plus(x, y) |
number_plus(object x, object y) |
|
object x, y; |
|
97 |
{ |
{ |
|
int i, j, k; |
|
98 |
double dx, dy; |
double dx, dy; |
99 |
object z, z1; |
object z; |
100 |
switch (type_of(x)) { |
switch (type_of(x)) { |
101 |
case t_fixnum: |
case t_fixnum: |
102 |
switch(type_of(y)) { |
switch(type_of(y)) { |
233 |
|
|
234 |
default: |
default: |
235 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
236 |
|
return(Cnil); |
237 |
} |
} |
238 |
} |
} |
239 |
|
|
240 |
object |
object |
241 |
one_plus(x) |
one_plus(object x) |
|
object x; |
|
242 |
{ |
{ |
|
int i; |
|
243 |
double dx; |
double dx; |
244 |
object z, z1; |
object z; |
245 |
|
|
246 |
|
|
247 |
switch (type_of(x)) { |
switch (type_of(x)) { |
272 |
return(z); |
return(z); |
273 |
|
|
274 |
case t_complex: |
case t_complex: |
|
COMPLEX: |
|
275 |
z = make_complex(one_plus(x->cmp.cmp_real), x->cmp.cmp_imag); |
z = make_complex(one_plus(x->cmp.cmp_real), x->cmp.cmp_imag); |
276 |
return(z); |
return(z); |
277 |
|
|
278 |
default: |
default: |
279 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
280 |
|
return(Cnil); |
281 |
} |
} |
282 |
} |
} |
283 |
|
|
284 |
object |
object |
285 |
number_minus(x, y) |
number_minus(object x, object y) |
|
object x, y; |
|
286 |
{ |
{ |
|
int i, j, k; |
|
287 |
double dx, dy; |
double dx, dy; |
288 |
object z, z1; |
object z; |
289 |
|
|
290 |
|
|
291 |
switch (type_of(x)) { |
switch (type_of(x)) { |
422 |
|
|
423 |
default: |
default: |
424 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
425 |
|
return(Cnil); |
426 |
} |
} |
427 |
} |
} |
428 |
|
|
429 |
object |
object |
430 |
one_minus(x) |
one_minus(object x) |
|
object x; |
|
431 |
{ |
{ |
|
int i; |
|
432 |
double dx; |
double dx; |
433 |
object z, z1; |
object z; |
434 |
switch (type_of(x)) { |
switch (type_of(x)) { |
435 |
|
|
436 |
case t_fixnum: |
case t_fixnum: |
455 |
return(z); |
return(z); |
456 |
|
|
457 |
case t_complex: |
case t_complex: |
|
COMPLEX: |
|
458 |
z = make_complex(one_minus(x->cmp.cmp_real), x->cmp.cmp_imag); |
z = make_complex(one_minus(x->cmp.cmp_real), x->cmp.cmp_imag); |
459 |
return(z); |
return(z); |
460 |
|
|
461 |
default: |
default: |
462 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
463 |
|
return(Cnil); |
464 |
} |
} |
465 |
} |
} |
466 |
|
|
467 |
object |
object |
468 |
number_negate(x) |
number_negate(object x) |
|
object x; |
|
469 |
{ |
{ |
470 |
object z, z1; |
object z, z1; |
471 |
|
|
502 |
|
|
503 |
default: |
default: |
504 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
505 |
|
return(Cnil); |
506 |
} |
} |
507 |
} |
} |
508 |
|
|
509 |
object |
object |
510 |
number_times(x, y) |
number_times(object x, object y) |
|
object x, y; |
|
511 |
{ |
{ |
512 |
object z; |
object z; |
513 |
double dx, dy; |
double dx, dy; |
652 |
|
|
653 |
default: |
default: |
654 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
655 |
|
return(Cnil); |
656 |
} |
} |
657 |
} |
} |
658 |
|
|
659 |
object |
object |
660 |
number_divide(x, y) |
number_divide(object x, object y) |
|
object x, y; |
|
661 |
{ |
{ |
662 |
object z; |
object z; |
663 |
double dx, dy; |
double dx, dy; |
800 |
|
|
801 |
default: |
default: |
802 |
FEwrong_type_argument(sLnumber, x); |
FEwrong_type_argument(sLnumber, x); |
803 |
|
return(Cnil); |
804 |
} |
} |
805 |
} |
} |
806 |
|
|
807 |
object |
object |
808 |
integer_divide1(x, y) |
integer_divide1(object x, object y) |
|
object x, y; |
|
809 |
{ |
{ |
810 |
object q, r; |
object q, r; |
811 |
|
|
814 |
} |
} |
815 |
|
|
816 |
object |
object |
817 |
get_gcd(x, y) |
get_gcd(object x, object y) |
|
object x, y; |
|
818 |
{ |
{ |
819 |
int i, j, k; |
int i, j, k; |
820 |
object q, r; |
object q, r; |
858 |
} |
} |
859 |
|
|
860 |
/* (+ ) */ |
/* (+ ) */ |
861 |
Lplus() |
void |
862 |
|
Lplus(void) |
863 |
{ |
{ |
864 |
int i, j; |
int i, j; |
865 |
|
|
875 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
876 |
} |
} |
877 |
|
|
878 |
Lminus() |
void |
879 |
|
Lminus(void) |
880 |
{ |
{ |
881 |
int i, j; |
int i, j; |
882 |
|
|
894 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
895 |
} |
} |
896 |
|
|
897 |
Ltimes() |
void |
898 |
|
Ltimes(void) |
899 |
{ |
{ |
900 |
int i, j; |
int i, j; |
901 |
|
|
911 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
912 |
} |
} |
913 |
|
|
914 |
Ldivide() |
void |
915 |
|
Ldivide(void) |
916 |
{ |
{ |
917 |
int i, j; |
int i, j; |
918 |
|
|
930 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
931 |
} |
} |
932 |
|
|
933 |
Lone_plus() |
void |
934 |
|
Lone_plus(void) |
935 |
{ |
{ |
|
object x; |
|
936 |
|
|
937 |
check_arg(1); |
check_arg(1); |
938 |
check_type_number(&vs_base[0]); |
check_type_number(&vs_base[0]); |
939 |
vs_base[0] = one_plus(vs_base[0]); |
vs_base[0] = one_plus(vs_base[0]); |
940 |
} |
} |
941 |
|
|
942 |
Lone_minus() |
void |
943 |
|
Lone_minus(void) |
944 |
{ |
{ |
|
object x; |
|
945 |
|
|
946 |
check_arg(1); |
check_arg(1); |
947 |
check_type_number(&vs_base[0]); |
check_type_number(&vs_base[0]); |
948 |
vs_base[0] = one_minus(vs_base[0]); |
vs_base[0] = one_minus(vs_base[0]); |
949 |
} |
} |
950 |
|
|
951 |
Lconjugate() |
void |
952 |
|
Lconjugate(void) |
953 |
{ |
{ |
954 |
object c, i; |
object c, i; |
955 |
|
|
960 |
i = number_negate(c->cmp.cmp_imag); |
i = number_negate(c->cmp.cmp_imag); |
961 |
vs_push(i); |
vs_push(i); |
962 |
vs_base[0] = make_complex(c->cmp.cmp_real, i); |
vs_base[0] = make_complex(c->cmp.cmp_real, i); |
963 |
vs_pop; |
vs_popp; |
964 |
} |
} |
965 |
} |
} |
966 |
|
|
967 |
Lgcd() |
void |
968 |
|
Lgcd(void) |
969 |
{ |
{ |
970 |
int i, narg; |
int i, narg; |
971 |
|
|
986 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
987 |
} |
} |
988 |
|
|
989 |
Llcm() |
void |
990 |
|
Llcm(void) |
991 |
{ |
{ |
992 |
object t, g; |
object t, g; |
993 |
int i, narg; |
int i, narg; |
1008 |
g = get_gcd(vs_base[0], vs_base[i]); |
g = get_gcd(vs_base[0], vs_base[i]); |
1009 |
vs_push(g); |
vs_push(g); |
1010 |
vs_base[0] = number_divide(t, g); |
vs_base[0] = number_divide(t, g); |
1011 |
vs_pop; |
vs_popp; |
1012 |
vs_pop; |
vs_popp; |
1013 |
} |
} |
1014 |
if (number_minusp(vs_base[0])) |
if (number_minusp(vs_base[0])) |
1015 |
vs_base[0] = number_negate(vs_base[0]); |
vs_base[0] = number_negate(vs_base[0]); |
1016 |
vs_top = vs_base+1; |
vs_top = vs_base+1; |
1017 |
} |
} |
1018 |
|
|
1019 |
zero_divisor() |
void |
1020 |
|
zero_divisor(void) |
1021 |
{ |
{ |
1022 |
FEerror("Zero divisor.", 0); |
FEerror("Zero divisor.", 0); |
1023 |
} |
} |
1024 |
|
|
1025 |
init_num_arith() |
void |
1026 |
|
init_num_arith(void) |
1027 |
{ |
{ |
1028 |
make_function("+", Lplus); |
make_function("+", Lplus); |
1029 |
make_function("-", Lminus); |
make_function("-", Lminus); |