Canola  0.8.D001
lib/number/z.h
Go to the documentation of this file.
00001 //
00002 // canola - canon canola 1614p emulator
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, version 3, as
00007 // published by the Free Software Foundation.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License along
00015 // with this program. If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef LIB_NUMBER_Z_H
00019 #define LIB_NUMBER_Z_H
00020 
00021 #include <lib/ac/stddef.h>
00022 #include <string>
00023 
00028 class number_z
00029 {
00030 public:
00035     ~number_z();
00036 
00041     number_z();
00042 
00049     number_z(unsigned long long rhs);
00050 
00057     number_z(unsigned long rhs);
00058 
00065     number_z(unsigned rhs);
00066 
00073     number_z(const number_z &rhs);
00074 
00081     number_z &operator=(const number_z &rhs);
00082 
00083     void clear(void);
00084 
00085     bool is_zero(void) const;
00086 
00087     bool is_not_zero(void) const { return !is_zero(); }
00088 
00089     bool is_one(void) const;
00090 
00091     number_z &operator+=(const number_z &rhs);
00092 
00093     number_z operator+(const number_z &rhs) const;
00094 
00095     number_z &operator-=(const number_z &rhs);
00096 
00097     number_z operator-(const number_z &rhs) const;
00098 
00099     number_z &operator*=(const number_z &rhs);
00100 
00101     number_z operator*(const number_z &rhs) const;
00102 
00103     number_z &operator/=(const number_z &rhs);
00104 
00105     number_z operator/(const number_z &rhs) const;
00106 
00107     number_z &operator%=(const number_z &rhs);
00108 
00109     number_z operator%(const number_z &rhs) const;
00110 
00123     number_z shift_left(size_t ndigits) const;
00124 
00137     number_z shift_right(size_t ndigits) const;
00138 
00139     bool operator<(const number_z &rhs) const;
00140 
00141     bool operator<=(const number_z &rhs) const;
00142 
00143     bool operator>(const number_z &rhs) const;
00144 
00145     bool operator>=(const number_z &rhs) const;
00146 
00147     bool operator==(const number_z &rhs) const;
00148 
00149     bool operator!=(const number_z &rhs) const;
00150 
00163     unsigned get(size_t digit_number) const;
00164 
00165     size_t get_digit_count(void) const { return digits_used; }
00166 
00172     number_z right_16(void) const;
00173 
00174     std::string representation(void) const;
00175 
00181     static number_z one(void);
00182 
00183     void print_me(const char *file, int line, const char *caption) const;
00184 
00194     void build(unsigned c);
00195 
00200     long to_long(void) const;
00201 
00202 private:
00209     size_t digits_used;
00210 
00216     size_t digits_allocated;
00217 
00218     typedef unsigned char digit_t;
00219 
00230     digit_t *digits;
00231 
00236     bool is_valid(void) const;
00237 
00248     void set(size_t dignum, unsigned digval);
00249 
00266     static bool div_mod(const number_z &numerator, const number_z &denominator,
00267         number_z &quotient, number_z &remainder);
00268 
00284     static int compare(const number_z &lhs, const number_z &rhs);
00285 };
00286 
00287 // vim: set ts=8 sw=4 et :
00288 #endif // LIB_NUMBER_Z_H