source: to-imperative/trunk/library/Arithm/div_rem.cc @ 1035

Last change on this file since 1035 was 1035, checked in by pooh, 18 years ago
  • Finished library changes for long arithmetic.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1// $Source$
2// $Revision: 1035 $
3// $Date: 2003-07-18 06:43:34 +0000 (Fri, 18 Jul 2003) $
4// $Author: pooh $
5
6#include <rf_core.hh>
7#include <rf_short_int.hh>
8#include <rf_integer.ih>
9#include <inttypes.h>
10#include <gmp.h>
11
12namespace refal
13{
14
15using namespace rfrt;
16using namespace rftype;
17
18namespace Arithm
19{
20
21RF_FUNC (Div_m_Rem, (RF_ARG s_Int1, s_Int2), (RF_RES s_Quo, s_Rem))
22
23  Term* p_Int1 = s_Int1.get_first();
24  Term* p_Int2 = s_Int2.get_first();
25
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) {
42    Integer* i1 = static_cast<Integer*>(p_Int1);
43    Expr r = Integer::create_expr(0);
44    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) {
50      Integer* i2 = static_cast<Integer*>(p_Int2);
51      s_Quo = Integer::create_expr(i1->div_rem(*i2, rp));
52      s_Rem = r;
53    } else {
54      RF_LIB_ERROR("Invalid argument");
55    }
56  } else {
57    RF_LIB_ERROR("Invalid argument");
58  }
59RF_END
60}
61
62}
Note: See TracBrowser for help on using the repository browser.