00001 00002 inline void N::sub(const N& a) 00003 { 00004 if(this == &a) 00005 { 00006 set(0); 00007 } 00008 else if(size) 00009 { 00010 if(a.size) 00011 { 00012 sub_large_large(a); 00013 } 00014 else 00015 { 00016 sub_large_small(a.limb); 00017 } 00018 } 00019 else 00020 { 00021 if(a.size) 00022 { 00023 throw result_negative_exception(__FILE__, __LINE__); 00024 } 00025 else 00026 { 00027 sub_small_small(a.limb); 00028 } 00029 } 00030 } 00031 00032 inline void N::sub(const N& a, const N& b) 00033 { 00034 if(&a == &b) 00035 { 00036 set(0); 00037 } 00038 else if(a.size) 00039 { 00040 if(b.size) 00041 { 00042 sub_large_large(a, b); 00043 } 00044 else 00045 { 00046 sub_large_small(a, b.limb); 00047 } 00048 } 00049 else 00050 { 00051 if(b.size) 00052 { 00053 throw result_negative_exception(__FILE__, __LINE__); 00054 } 00055 else 00056 { 00057 sub_small_small(a.limb, b.limb); 00058 } 00059 } 00060 } 00061 00062 inline void N::sub_one() 00063 { 00064 if(size) 00065 { 00066 sub_one_large(); 00067 } 00068 else 00069 { 00070 sub_one_small(); 00071 } 00072 } 00073 00074 // 00075 // Operators 00076 // 00077 00078 inline N operator-(const N& a, const N& b) 00079 { 00080 N r; 00081 r.sub(a, b); 00082 return r; 00083 } 00084 00085 inline N& N::operator-=(const N& rhs) 00086 { 00087 sub(rhs); 00088 return *this; 00089 } 00090 00091 inline N& N::operator--() 00092 { 00093 sub_one(); 00094 return *this; 00095 } 00096 00097 inline N N::operator--(int) 00098 { 00099 N copy(*this); 00100 sub_one(); 00101 return copy; 00102 } 00103 00104 // 00105 // Algorithms 00106 // 00107 00108 inline void N::sub_small_small(const limb_t a, const limb_t b) 00109 { 00110 limb = a - b; 00111 if(limb > a) 00112 { 00113 throw result_negative_exception(__FILE__, __LINE__); 00114 } 00115 } 00116 00117 inline void N::sub_small_small(const limb_t a) 00118 { 00119 limb_t old = limb; 00120 limb -= a; 00121 if(limb > old) 00122 { 00123 throw result_negative_exception(__FILE__, __LINE__); 00124 } 00125 } 00126 00127 inline void N::sub_one_small() 00128 { 00129 limb_t old = limb; 00130 limb--; 00131 if(limb > old) 00132 { 00133 throw result_negative_exception(__FILE__, __LINE__); 00134 } 00135 }
Copyright © 2007-2008 Remco Bloemen.
Generated on Tue Jan 22 17:35:31 2008 for symbolism by doxygen 1.5.4