/[gcl]/gcl/o/num_arith.c
ViewVC logotype

Diff of /gcl/o/num_arith.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by camm, Mon Aug 23 17:29:15 2004 UTC revision 1.15 by camm, Wed Aug 25 03:10:14 2004 UTC
# Line 100  integer_exact_quotient(object x,object y Line 100  integer_exact_quotient(object x,object y
100    
101    object r;    object r;
102    
103    if (y==small_fixnum(1))    if (y==small_fixnum(1) || x==small_fixnum(0))
104      return x;      return x;
105    
106    if (type_of(y)==t_fixnum && type_of(x)==t_fixnum)    if (type_of(y)==t_fixnum && type_of(x)==t_fixnum)
# Line 120  integer_exact_quotient(object x,object y Line 120  integer_exact_quotient(object x,object y
120  static object  static object
121  ratio_op_with_cancellation(object a,object b,object c,object d,object (*op)(object,object)) {  ratio_op_with_cancellation(object a,object b,object c,object d,object (*op)(object,object)) {
122    
123    object b0,d0,g,t,g1,r;    object b0,d0,g,t,g1;
124        
125    b0=b;    b0=b;
126    d0=d;    d0=d;
# Line 139  ratio_op_with_cancellation(object a,obje Line 139  ratio_op_with_cancellation(object a,obje
139    
140    b=number_times(b,d);    b=number_times(b,d);
141        
142    r=alloc_object(t_ratio);    return make_ratio(t,b,1);
   r->rat.rat_num=t;  
   r->rat.rat_den=b;  
   
   return r;  
143        
144  }  }
145    
# Line 151  ratio_op_with_cancellation(object a,obje Line 147  ratio_op_with_cancellation(object a,obje
147  static object  static object
148  ratio_mult_with_cancellation(object a,object b,object c,object d) {  ratio_mult_with_cancellation(object a,object b,object c,object d) {
149    
150    object g,r;    object g;
151        
152    g=get_gcd(a,d);    g=get_gcd(a,d);
153        
# Line 163  ratio_mult_with_cancellation(object a,ob Line 159  ratio_mult_with_cancellation(object a,ob
159    b=integer_exact_quotient(b,g,0);    b=integer_exact_quotient(b,g,0);
160    c=integer_exact_quotient(c,g,0);    c=integer_exact_quotient(c,g,0);
161    
162    r=alloc_object(t_ratio);    a=number_times(a,c);
163    r->rat.rat_num=number_times(a,c);    b=number_times(b,d);
   r->rat.rat_den=number_times(b,d);  
164    
165    return r;    return make_ratio(a,b,1);
166        
167  }  }
168    
# Line 744  number_divide(object x, object y) Line 739  number_divide(object x, object y)
739                  switch (type_of(y)) {                  switch (type_of(y)) {
740                  case t_fixnum:                  case t_fixnum:
741                  case t_bignum:                  case t_bignum:
742                          if(number_zerop(y) == TRUE)  /*                      if(number_zerop(y) == TRUE) */
743                                  zero_divisor();  /*                              zero_divisor(); */
744                          if (number_minusp(y) == TRUE) {  /*                      if (number_minusp(y) == TRUE) { */
745                                  x = number_negate(x);  /*                              x = number_negate(x); */
746                                  y = number_negate(y);  /*                              y = number_negate(y); */
747                          }  /*                      } */
748                          z = make_ratio(x, y);  /*                      z = make_ratio(x, y, 0); */
749                          return(z);                          return(make_ratio(x, y, 0));
750                  case t_ratio:                  case t_ratio:
751                          if(number_zerop(y->rat.rat_num))                          if(number_zerop(y->rat.rat_num))
752                                  zero_divisor();                                  zero_divisor();

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26