numerix_doc 0.4
|
00001 00002 #include <numerix/integer.hpp> 00003 #include <basix/literal.hpp> 00004 #include <basix/glue.hpp> 00005 00006 namespace mmx { 00007 static integer 00008 GLUE_1 (const literal &arg_1) { 00009 return make_literal_integer (arg_1); 00010 } 00011 00012 static generic 00013 GLUE_2 (const int &arg_1) { 00014 return integer_construct (arg_1); 00015 } 00016 00017 static integer 00018 GLUE_3 (const int &arg_1) { 00019 return integer (arg_1); 00020 } 00021 00022 static int 00023 GLUE_4 (const integer &arg_1) { 00024 return as_int (arg_1); 00025 } 00026 00027 static integer 00028 GLUE_5 (const int &arg_1) { 00029 return integer (arg_1); 00030 } 00031 00032 static integer 00033 GLUE_6 (const string &arg_1) { 00034 return integer (arg_1); 00035 } 00036 00037 static string 00038 GLUE_7 (const integer &arg_1) { 00039 return as_string (arg_1); 00040 } 00041 00042 static integer 00043 GLUE_8 (const integer &arg_1) { 00044 return -arg_1; 00045 } 00046 00047 static integer 00048 GLUE_9 (const integer &arg_1) { 00049 return square (arg_1); 00050 } 00051 00052 static integer 00053 GLUE_10 (const integer &arg_1, const integer &arg_2) { 00054 return arg_1 + arg_2; 00055 } 00056 00057 static integer 00058 GLUE_11 (const integer &arg_1, const integer &arg_2) { 00059 return arg_1 - arg_2; 00060 } 00061 00062 static integer 00063 GLUE_12 (const integer &arg_1, const integer &arg_2) { 00064 return arg_1 * arg_2; 00065 } 00066 00067 static integer 00068 GLUE_13 (const integer &arg_1, const integer &arg_2) { 00069 return arg_1 / arg_2; 00070 } 00071 00072 static integer 00073 GLUE_14 (const integer &arg_1, const integer &arg_2) { 00074 return quo (arg_1, arg_2); 00075 } 00076 00077 static integer 00078 GLUE_15 (const integer &arg_1, const integer &arg_2) { 00079 return rem (arg_1, arg_2); 00080 } 00081 00082 static bool 00083 GLUE_16 (const integer &arg_1, const integer &arg_2) { 00084 return divides (arg_1, arg_2); 00085 } 00086 00087 static integer 00088 GLUE_17 (const integer &arg_1, const integer &arg_2) { 00089 return gcd (arg_1, arg_2); 00090 } 00091 00092 static integer 00093 GLUE_18 (const integer &arg_1, const integer &arg_2) { 00094 return lcm (arg_1, arg_2); 00095 } 00096 00097 static bool 00098 GLUE_19 (const integer &arg_1, const integer &arg_2) { 00099 return arg_1 < arg_2; 00100 } 00101 00102 static bool 00103 GLUE_20 (const integer &arg_1, const integer &arg_2) { 00104 return arg_1 <= arg_2; 00105 } 00106 00107 static bool 00108 GLUE_21 (const integer &arg_1, const integer &arg_2) { 00109 return arg_1 > arg_2; 00110 } 00111 00112 static bool 00113 GLUE_22 (const integer &arg_1, const integer &arg_2) { 00114 return arg_1 >= arg_2; 00115 } 00116 00117 static integer 00118 GLUE_23 (const integer &arg_1) { 00119 return abs (arg_1); 00120 } 00121 00122 static integer 00123 GLUE_24 (const integer &arg_1, const integer &arg_2) { 00124 return min (arg_1, arg_2); 00125 } 00126 00127 static integer 00128 GLUE_25 (const integer &arg_1, const integer &arg_2) { 00129 return max (arg_1, arg_2); 00130 } 00131 00132 static integer 00133 GLUE_26 (const integer &arg_1) { 00134 return factorial (arg_1); 00135 } 00136 00137 static integer 00138 GLUE_27 (const integer &arg_1, const integer &arg_2) { 00139 return binomial (arg_1, arg_2); 00140 } 00141 00142 static bool 00143 GLUE_28 (const integer &arg_1) { 00144 return is_probable_prime (arg_1); 00145 } 00146 00147 static integer 00148 GLUE_29 (const integer &arg_1) { 00149 return probable_next_prime (arg_1); 00150 } 00151 00152 static integer 00153 GLUE_30 (const integer &arg_1, const integer &arg_2) { 00154 return arg_1 & arg_2; 00155 } 00156 00157 static integer 00158 GLUE_31 (const integer &arg_1, const integer &arg_2) { 00159 return arg_1 | arg_2; 00160 } 00161 00162 static integer 00163 GLUE_32 (const integer &arg_1, const integer &arg_2) { 00164 return arg_1 ^ arg_2; 00165 } 00166 00167 static integer 00168 GLUE_33 (const integer &arg_1) { 00169 return ~arg_1; 00170 } 00171 00172 static int 00173 GLUE_34 (const integer &arg_1) { 00174 return bit_size (arg_1); 00175 } 00176 00177 static bool 00178 GLUE_35 (const integer &arg_1, const int &arg_2) { 00179 return arg_1[arg_2]; 00180 } 00181 00182 static int 00183 GLUE_36 (const integer &arg_1) { 00184 return hamming_norm (arg_1); 00185 } 00186 00187 static int 00188 GLUE_37 (const integer &arg_1, const integer &arg_2) { 00189 return hamming_distance (arg_1, arg_2); 00190 } 00191 00192 void 00193 glue_integer () { 00194 static bool done = false; 00195 if (done) return; 00196 done = true; 00197 define_type<integer > (lit ("Integer")); 00198 define ("literal_integer", GLUE_1); 00199 define_constructor<int > (GLUE_2); 00200 define ("integer", GLUE_3); 00201 define_converter ("upgrade", GLUE_4, PENALTY_INCLUSION); 00202 define_converter (":>", GLUE_5, PENALTY_CAST); 00203 define ("as_integer", GLUE_6); 00204 define ("as_string", GLUE_7); 00205 define ("-", GLUE_8); 00206 define ("square", GLUE_9); 00207 define ("+", GLUE_10); 00208 define ("-", GLUE_11); 00209 define ("*", GLUE_12); 00210 define ("div", GLUE_13); 00211 define ("quo", GLUE_14); 00212 define ("rem", GLUE_15); 00213 define ("divides?", GLUE_16); 00214 define ("gcd", GLUE_17); 00215 define ("lcm", GLUE_18); 00216 define ("<", GLUE_19); 00217 define ("<=", GLUE_20); 00218 define (">", GLUE_21); 00219 define (">=", GLUE_22); 00220 define ("abs", GLUE_23); 00221 define ("min", GLUE_24); 00222 define ("max", GLUE_25); 00223 define (".!", GLUE_26); 00224 define ("binomial", GLUE_27); 00225 define ("probable_prime?", GLUE_28); 00226 define ("probable_next_prime", GLUE_29); 00227 define ("/\\", GLUE_30); 00228 define ("\\/", GLUE_31); 00229 define ("xor", GLUE_32); 00230 define ("!", GLUE_33); 00231 define ("#", GLUE_34); 00232 define (".[]", GLUE_35); 00233 define ("hamming_norm", GLUE_36); 00234 define ("hamming_distance", GLUE_37); 00235 } 00236 }