Canola
0.8.D001
|
00001 // 00002 // canola - canon canola 1614p emulator 00003 // Copyright (C) 2011, 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_H 00019 #define LIB_NUMBER_H 00020 00021 #include <lib/config.h> 00022 #include <string> 00023 00024 #include <lib/display.h> 00025 #include <lib/number/z.h> 00026 00027 00035 class number 00036 { 00037 public: 00042 ~number(); 00043 00048 number(); 00049 00056 number(const number &rhs); 00057 00064 number(long rhs); 00065 00072 number &operator=(const number &rhs); 00073 00081 void operator+=(const number &rhs); 00082 00090 number operator+(const number &rhs) const; 00091 00099 void operator-=(const number &rhs); 00100 00108 number operator-(const number &rhs) const; 00109 00114 number operator-(void) const; 00115 00123 void operator*=(const number &rhs); 00124 00132 number operator*(const number &rhs) const; 00133 00141 void operator/=(const number &rhs); 00142 00149 number operator/(const number &rhs) const; 00150 00155 number sqrt(void) const; 00156 00162 long to_long(void) const; 00163 00172 number round_up(int preferred_decimal) const; 00173 00182 number round_off(int preferred_decimal) const; 00183 00192 number round_down(int preferred_decimal) const; 00193 00198 std::string to_string(void) const; 00199 00205 display get_display(void) const; 00206 00213 void right_shift(void); 00214 00221 bool operator==(const number &rhs) const; 00222 00229 bool operator!=(const number &rhs) const; 00230 00237 bool operator<(const number &rhs) const; 00238 00245 bool operator<=(const number &rhs) const; 00246 00253 bool operator>(const number &rhs) const; 00254 00261 bool operator>=(const number &rhs) const; 00262 00269 int sign(void) const; 00270 00275 number fabs(void) const; 00276 00281 void insert_digit_before_dot(int n); 00282 00287 void insert_digit_after_dot(int n); 00288 00293 void insert_dot(void); 00294 00300 bool has_overflowed(void) const; 00301 00307 static number infinity(void); 00308 00309 private: 00315 number_z value; 00316 00322 unsigned decimal; 00323 00328 bool negative; 00329 00330 static unsigned max(unsigned a, unsigned b) { return (a > b ? a : b); } 00331 00332 static int max(int a, int b) { return (a > b ? a : b); } 00333 00337 void clear(void); 00338 00343 bool is_zero(void) const; 00344 00354 void print_me(const char *file, int line) const; 00355 00366 number(const number_z &value, unsigned decimal, bool negative = false); 00367 00373 static number positive_minus_positive(const number &lhs, const number &rhs); 00374 00380 static number positive_plus_positive(const number &lhs, const number &rhs); 00381 00387 static void truncate_floating_operation(number_z &t3, unsigned &t3ndec); 00388 00394 static void strip_redundant_decimal_places(number_z &t3, unsigned &t3ndec); 00395 }; 00396 00397 // vim: set ts=8 sw=4 et : 00398 #endif // LIB_NUMBER_H