source: to-imperative/trunk/library/Arithm/mult.cc @ 1027

Last change on this file since 1027 was 1027, checked in by pooh, 18 years ago
  • Most long arithmetic functions implemented.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1// $Source$
2// $Revision: 1027 $
3// $Date: 2003-07-17 12:15:17 +0000 (Thu, 17 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 (_a_, (RF_ARG s_Int1, s_Int2), (RF_RES s_Res))
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      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) {
42    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) {
47      Integer* i2 = static_cast<Integer*>(p_Int2);
48      s_Res = Integer::create_expr((*i1) * (*i2));
49    } else {
50      RF_LIB_ERROR("Invalid argument");
51    }
52  } else {
53    RF_LIB_ERROR("Invalid argument");
54  }
55RF_END
56}
57
58}
Note: See TracBrowser for help on using the repository browser.