Changeset 1105


Ignore:
Timestamp:
Aug 6, 2003, 5:27:37 PM (17 years ago)
Author:
luba
Message:
Location:
to-imperative/trunk/library/Arithm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Arithm/add.cc

    r1027 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       if ((((i1 > 0) && (i2 > 0)) || ((i1 < 0) && (i2 < 0))) &&
    31           imaxabs(i1) >= INTPTR_MAX - imaxabs(i2)
    32       ) {
    33         s_Res = Integer::create_expr(i1 + Integer(i2));
    34       } else {
    35         s_Res = ShortInt::create_expr(i1 + i2);
    36       }
    37     } else if (p_Int2->get_type() == type_int) {
    38       Integer* i2 = static_cast<Integer*>(p_Int2);
    39       s_Res = Integer::create_expr(i1 + (*i2));
    40     } else {
    41       RF_LIB_ERROR("Invalid argument");
    42     }
    43   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    4424    Integer* i1 = static_cast<Integer*>(p_Int1);
    45     if (p_Int2->get_type() == type_short_int) {
    46       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    47       s_Res = Integer::create_expr((*i1) + i2);
    48     } else if (p_Int2->get_type() == type_int) {
     25    if (p_Int2->get_type() == type_int) {
    4926      Integer* i2 = static_cast<Integer*>(p_Int2);
    5027      s_Res = Integer::create_expr((*i1) + (*i2));
  • to-imperative/trunk/library/Arithm/div.cc

    r1027 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       s_Res = ShortInt::create_expr(i1 / i2);
    31     } else if (p_Int2->get_type() == type_int) {
    32       Integer* i2 = static_cast<Integer*>(p_Int2);
    33       s_Res = Integer::create_expr(i1 / (*i2));
    34     } else {
    35       RF_LIB_ERROR("Invalid argument");
    36     }
    37   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    3824    Integer* i1 = static_cast<Integer*>(p_Int1);
    39     if (p_Int2->get_type() == type_short_int) {
    40       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    41       s_Res = Integer::create_expr((*i1) / i2);
    42     } else if (p_Int2->get_type() == type_int) {
     25    if (p_Int2->get_type() == type_int) {
    4326      Integer* i2 = static_cast<Integer*>(p_Int2);
    4427      s_Res = Integer::create_expr((*i1) / (*i2));
  • to-imperative/trunk/library/Arithm/div_rem.cc

    r1035 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       s_Quo = ShortInt::create_expr(i1 / i2);
    31       s_Rem = ShortInt::create_expr(i1 % i2);
    32     } else if (p_Int2->get_type() == type_int) {
    33       Integer* i2 = static_cast<Integer*>(p_Int2);
    34       Expr r = Integer::create_expr(0);
    35       Integer* rp = static_cast<Integer*>(r.get_first());
    36       s_Quo = Integer::create_expr(div_rem(i1, *i2, rp));
    37       s_Rem = r;
    38     } else {
    39       RF_LIB_ERROR("Invalid argument");
    40     }
    41   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    4224    Integer* i1 = static_cast<Integer*>(p_Int1);
    4325    Expr r = Integer::create_expr(0);
    4426    Integer* rp = static_cast<Integer*>(r.get_first());
    45     if (p_Int2->get_type() == type_short_int) {
    46       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    47       s_Quo = Integer::create_expr(i1->div_rem(i2, rp));
    48       s_Rem = r;
    49     } else if (p_Int2->get_type() == type_int) {
     27    if (p_Int2->get_type() == type_int) {
    5028      Integer* i2 = static_cast<Integer*>(p_Int2);
    5129      s_Quo = Integer::create_expr(i1->div_rem(*i2, rp));
  • to-imperative/trunk/library/Arithm/gcd.cc

    r1035 r1105  
    2525  Expr e1, e2;
    2626
    27   if (p_Int1->get_type() == type_short_int) {
    28     intptr_t n = static_cast<ShortInt*>(p_Int1)->to_int();
    29     if (n < 0) e1 = ShortInt::create_expr(-n);
    30     else e1 = s_Int1;
    31   } else if (p_Int1->get_type() == type_int) {
     27  if (p_Int1->get_type() == type_int) {
    3228    Integer* n = static_cast<Integer*>(p_Int1);
    3329    if (n->sign() < 0) e1 = Integer::create_expr(-(*n));
     
    3632    RF_LIB_ERROR("Invalid argument");
    3733  }
    38   if (p_Int2->get_type() == type_short_int) {
    39     intptr_t n = static_cast<ShortInt*>(p_Int2)->to_int();
    40     if (n < 0) e2 = ShortInt::create_expr(-n);
    41     else e2 = s_Int2;
    42   } else if (p_Int2->get_type() == type_int) {
     34  if (p_Int2->get_type() == type_int) {
    4335    Integer* n = static_cast<Integer*>(p_Int2);
    4436    if (n->sign() < 0) e2 = Integer::create_expr(-(*n));
     
    5143  while (true) {
    5244    p_Int2 = e2.get_first();
    53     if (p_Int2->get_type() == type_short_int) {
    54       if (static_cast<ShortInt*>(p_Int2)->to_int() == 0) break;
    55     } else if (p_Int2->get_type() == type_int) {
     45    if (p_Int2->get_type() == type_int) {
    5646      if (static_cast<Integer*>(p_Int2)->sign() == 0) break;
    5747    }
  • to-imperative/trunk/library/Arithm/mult.cc

    r1027 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       if (imaxabs(i1) < INTPTR_MAX / imaxabs(i2)) {
    31         s_Res = ShortInt::create_expr(i1 * i2);
    32       } else {
    33         s_Res = Integer::create_expr(i1 * Integer(i2));
    34       }
    35     } else if (p_Int2->get_type() == type_int) {
    36       Integer* i2 = static_cast<Integer*>(p_Int2);
    37       s_Res = Integer::create_expr(i1 * (*i2));
    38     } else {
    39       RF_LIB_ERROR("Invalid argument");
    40     }
    41   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    4224    Integer* i1 = static_cast<Integer*>(p_Int1);
    43     if (p_Int2->get_type() == type_short_int) {
    44       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    45       s_Res = Integer::create_expr((*i1) * i2);
    46     } else if (p_Int2->get_type() == type_int) {
     25    if (p_Int2->get_type() == type_int) {
    4726      Integer* i2 = static_cast<Integer*>(p_Int2);
    4827      s_Res = Integer::create_expr((*i1) * (*i2));
  • to-imperative/trunk/library/Arithm/neg.cc

    r1035 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2320  Term* p_Int1 = s_Int1.get_first();
    2421
    25   if (p_Int1->get_type() == type_short_int) {
    26     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    27     s_Res = ShortInt::create_expr(-i1);
    28   } else if (p_Int1->get_type() == type_int) {
     22  if (p_Int1->get_type() == type_int) {
    2923    Integer* i1 = static_cast<Integer*>(p_Int1);
    3024    s_Res = Integer::create_expr(-(*i1));
  • to-imperative/trunk/library/Arithm/rem.cc

    r1027 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       s_Res = ShortInt::create_expr(i1 % i2);
    31     } else if (p_Int2->get_type() == type_int) {
    32       Integer* i2 = static_cast<Integer*>(p_Int2);
    33       s_Res = Integer::create_expr(i1 % (*i2));
    34     } else {
    35       RF_LIB_ERROR("Invalid argument");
    36     }
    37   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    3824    Integer* i1 = static_cast<Integer*>(p_Int1);
    39     if (p_Int2->get_type() == type_short_int) {
    40       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    41       s_Res = Integer::create_expr((*i1) % i2);
    42     } else if (p_Int2->get_type() == type_int) {
     25    if (p_Int2->get_type() == type_int) {
    4326      Integer* i2 = static_cast<Integer*>(p_Int2);
    4427      s_Res = Integer::create_expr((*i1) % (*i2));
  • to-imperative/trunk/library/Arithm/sub.cc

    r1027 r1105  
    55
    66#include <rf_core.hh>
    7 #include <rf_short_int.hh>
    87#include <rf_integer.ih>
    9 #include <inttypes.h>
    10 #include <gmp.h>
    118
    129namespace refal
     
    2421  Term* p_Int2 = s_Int2.get_first();
    2522
    26   if (p_Int1->get_type() == type_short_int) {
    27     intptr_t i1 = static_cast<ShortInt*>(p_Int1)->to_int();
    28     if (p_Int2->get_type() == type_short_int) {
    29       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    30       if ((((i1 > 0) && (i2 < 0)) || ((i1 < 0) && (i2 > 0))) &&
    31           imaxabs(i1) >= INTPTR_MAX - imaxabs(i2)
    32       ) {
    33         s_Res = Integer::create_expr(i1 - Integer(i2));
    34       } else {
    35         s_Res = ShortInt::create_expr(i1 - i2);
    36       }
    37     } else if (p_Int2->get_type() == type_int) {
    38       Integer* i2 = static_cast<Integer*>(p_Int2);
    39       s_Res = Integer::create_expr(i1 - (*i2));
    40     } else {
    41       RF_LIB_ERROR("Invalid argument");
    42     }
    43   } else if (p_Int1->get_type() == type_int) {
     23  if (p_Int1->get_type() == type_int) {
    4424    Integer* i1 = static_cast<Integer*>(p_Int1);
    45     if (p_Int2->get_type() == type_short_int) {
    46       intptr_t i2 = static_cast<ShortInt*>(p_Int2)->to_int();
    47       s_Res = Integer::create_expr((*i1) - i2);
    48     } else if (p_Int2->get_type() == type_int) {
     25    if (p_Int2->get_type() == type_int) {
    4926      Integer* i2 = static_cast<Integer*>(p_Int2);
    5027      s_Res = Integer::create_expr((*i1) - (*i2));
Note: See TracChangeset for help on using the changeset viewer.