/*
Copyright (c) 1995, 1996, 1997 Stanford University
All rights reserved.
This software is provided under the terms described in
the "suif_copyright.h" include file.
*/
#include "MString.h"
#ifdef NO_FORWARDING
#include <iostream.h>
#else
class ostream;
class istream;
#endif
#ifndef COMMON_I_INTEGER_H
#define COMMON_I_INTEGER_H
#include <stdio.h>
#include <limits.h>
class StringInteger;
class IInteger
{
private:
enum IIntegerTag
{
IIT_C_INT, IIT_STRING_INT, IIT_POS_INFINITY, IIT_NEG_INFINITY,
IIT_SIGNLESS_INFINITY, IIT_UNDETERMINED
};
IIntegerTag _tag;
union
{
long long_val;
StringInteger *si_val; // eventually, this will be a vector<char>
} _value;
IInteger(StringInteger *initial_value);
public:
IInteger(void);
IInteger(signed char initial_value);
IInteger(unsigned char initial_value);
IInteger(short initial_value);
IInteger(unsigned short initial_value);
IInteger(int initial_value);
IInteger(unsigned int initial_value);
IInteger(long initial_value);
IInteger(unsigned long initial_value);
#ifdef LONGLONG
IInteger(LONGLONG initial_value);
IInteger(unsigned LONGLONG initial_value);
#endif
IInteger(const IInteger &initial_value);
IInteger(const char *initial_string, int base = 10);
~IInteger();
bool is_undetermined(void) const;
bool is_signless_infinity(void) const;
bool is_finite(void) const;
bool is_negative(void) const;
bool is_c_string_int(void) const;
bool is_c_char(void) const;
bool is_c_unsigned_char(void) const;
bool is_c_signed_char(void) const;
bool is_c_short(void) const;
bool is_c_unsigned_short(void) const;
bool is_c_int(void) const;
bool is_c_unsigned_int(void) const;
bool is_c_long(void) const;
bool is_c_unsigned_long(void) const;
#ifdef LONGLONG
bool is_c_long_long(void) const;
bool is_c_unsigned_long_long(void) const;
#endif
bool is_c_size_t(void) const;
char* c_string_int(void) const;
char c_char(void) const;
unsigned char c_unsigned_char(void) const;
signed char c_signed_char(void) const;
short c_short(void) const;
unsigned short c_unsigned_short(void) const;
int c_int(void) const;
unsigned int c_unsigned_int(void) const;
long c_long(void) const;
unsigned long c_unsigned_long(void) const;
#ifdef LONGLONG
long c_long_long(void) const;
unsigned long c_unsigned_long_long(void) const;
#endif
size_t c_size_t(void) const;
double c_double(void) const;
void set_c_char(char new_value);
void set_c_unsigned_char(unsigned char new_value);
void set_c_signed_char(signed char new_value);
void set_c_short(short new_value);
void set_c_unsigned_short(unsigned short new_value);
void set_c_int(int new_value);
void set_c_unsigned_int(unsigned int new_value);
void set_c_long(long new_value);
void set_c_unsigned_long(unsigned long new_value);
#ifdef LONGLONG
void set_c_long_long(LONGLONG new_value);
void set_c_unsigned_long_long(unsigned LONGLONG new_value);
#endif
void set_c_size_t(size_t new_value);
void set_integer(const IInteger &new_value);
void clear(void);
void write(ostream *out, int base = 10) const;
void write(String &str, int base) const;
String to_String(int base = 10) const;
// Reading from an istream
void read(const char *location, int base = 10);
void read(istream *in, int base = 10);
IInteger written_length(int base = 10) const;
void write(char *location, int base = 10) const;
char *to_string(int base = 10) const; // create a new char *
void print(ostream *in, int base = 10) const;
bool is_divisible_by(const IInteger &other) const;
IInteger add(const IInteger &other) const;
IInteger subtract(const IInteger &other) const;
IInteger multiply(const IInteger &other) const;
IInteger div(const IInteger &other) const;
IInteger mod(const IInteger &other) const;
IInteger negate(void) const;
IInteger &operator=(const IInteger &other);
bool operator==(const IInteger &other) const;
bool operator!=(const IInteger &other) const;
bool operator<(const IInteger &other) const;
bool operator>(const IInteger &other) const;
bool operator<=(const IInteger &other) const;
bool operator>=(const IInteger &other) const;
/*
* We now only compare with longs
* or unsigned longs
*/
bool operator==(int other) const;
bool operator!=(int other) const;
bool operator<(int other) const;
bool operator>(int other) const;
bool operator<=(int other) const;
bool operator>=(int other) const;
bool operator==(unsigned int other) const;
bool operator!=(unsigned int other) const;
bool operator<(unsigned int other) const;
bool operator>(unsigned int other) const;
bool operator<=(unsigned int other) const;
bool operator>=(unsigned int other) const;
bool operator==(long other) const;
bool operator!=(long other) const;
bool operator<(long other) const;
bool operator>(long other) const;
bool operator<=(long other) const;
bool operator>=(long other) const;
bool operator==(unsigned long other) const;
bool operator!=(unsigned long other) const;
bool operator<(unsigned long other) const;
bool operator>(unsigned long other) const;
bool operator<=(unsigned long other) const;
bool operator>=(unsigned long other) const;
IInteger operator+(const IInteger &other) const;
IInteger operator-(const IInteger &other) const;
IInteger operator*(const IInteger &other) const;
IInteger operator/(const IInteger &other) const;
IInteger operator%(const IInteger &other) const;
IInteger operator^(const IInteger &other) const;
IInteger operator&(const IInteger &other) const;
IInteger operator|(const IInteger &other) const;
IInteger operator~(void) const;
IInteger operator<<(const IInteger &other) const;
IInteger operator>>(const IInteger &other) const;
bool operator!(void) const;
bool operator&&(const IInteger &other) const;
bool operator||(const IInteger &other) const;
/* unary */
IInteger operator+(void) const;
IInteger operator-(void) const;
IInteger &operator+=(const IInteger &other);
IInteger &operator-=(const IInteger &other);
IInteger &operator*=(const IInteger &other);
IInteger &operator/=(const IInteger &other);
IInteger &operator%=(const IInteger &other);
IInteger &operator^=(const IInteger &other);
IInteger &operator&=(const IInteger &other);
IInteger &operator|=(const IInteger &other);
IInteger &operator>>=(const IInteger &other);
IInteger &operator<<=(const IInteger &other);
/* prefix */
IInteger &operator++(void);
IInteger &operator--(void);
/* postfix */
IInteger operator++(int);
IInteger operator--(int);
static IInteger ii_gcd(const IInteger &op1, const IInteger &op2);
static IInteger ii_gcd(const IInteger &op1, const IInteger &op2,
IInteger *coeff1, IInteger *coeff2);
static IInteger i_positive_inf(void);
static IInteger i_negative_inf(void);
static IInteger i_signless_inf(void);
};
inline IInteger zero(IInteger *) { return 0; }
extern IInteger i_positive_inf(void);
extern IInteger i_negative_inf(void);
extern IInteger i_signless_inf(void);
#endif /* COMMON_I_INTEGER_H */