00001
00002 #include <basix/int.hpp>
00003 #include <basix/vector.hpp>
00004 #include <basix/port.hpp>
00005 #include <basix/literal.hpp>
00006 #include <numerix/integer.hpp>
00007 #include <numerix/modular.hpp>
00008 #include <numerix/modular_integer.hpp>
00009 #include <numerix/rational.hpp>
00010 #include <numerix/floating.hpp>
00011 #include <basix/alias.hpp>
00012 #include <basix/glue.hpp>
00013
00014 #define int_literal(x) as_int (as_string (x))
00015 #define is_generic_literal is<literal>
00016 #define gen_literal_apply(f,v) gen (as<generic> (f), v)
00017 #define gen_literal_access(f,v) access (as<generic> (f), v)
00018
00019 namespace mmx {
00020 static mmx_floating
00021 GLUE_1 (const literal &arg_1) {
00022 return make_literal_floating (arg_1);
00023 }
00024
00025 static mmx_floating
00026 GLUE_2 (const int &arg_1) {
00027 return mmx_floating (arg_1);
00028 }
00029
00030 static mmx_floating
00031 GLUE_3 (const integer &arg_1) {
00032 return mmx_floating (arg_1);
00033 }
00034
00035 static mmx_floating
00036 GLUE_4 (const rational &arg_1) {
00037 return mmx_floating (arg_1);
00038 }
00039
00040 static mmx_floating
00041 GLUE_5 (const int &arg_1) {
00042 return mmx_floating (arg_1);
00043 }
00044
00045 static mmx_floating
00046 GLUE_6 (const double &arg_1) {
00047 return mmx_floating (arg_1);
00048 }
00049
00050 static mmx_floating
00051 GLUE_7 (const integer &arg_1) {
00052 return mmx_floating (arg_1);
00053 }
00054
00055 static mmx_floating
00056 GLUE_8 (const rational &arg_1) {
00057 return mmx_floating (arg_1);
00058 }
00059
00060 static mmx_floating
00061 GLUE_9 (const string &arg_1) {
00062 return mmx_floating (arg_1);
00063 }
00064
00065 static int
00066 GLUE_10 (const mmx_floating &arg_1) {
00067 return as_int (arg_1);
00068 }
00069
00070 static double
00071 GLUE_11 (const mmx_floating &arg_1) {
00072 return as_double (arg_1);
00073 }
00074
00075 static integer
00076 GLUE_12 (const mmx_floating &arg_1) {
00077 return as_integer (arg_1);
00078 }
00079
00080 static string
00081 GLUE_13 (const mmx_floating &arg_1) {
00082 return as_string (arg_1);
00083 }
00084
00085 static mmx_floating
00086 GLUE_14 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00087 return uniform_deviate (arg_1, arg_2);
00088 }
00089
00090 static mmx_floating
00091 GLUE_15 (const mmx_floating &arg_1) {
00092 return -arg_1;
00093 }
00094
00095 static mmx_floating
00096 GLUE_16 (const mmx_floating &arg_1) {
00097 return square (arg_1);
00098 }
00099
00100 static mmx_floating
00101 GLUE_17 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00102 return arg_1 + arg_2;
00103 }
00104
00105 static mmx_floating
00106 GLUE_18 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00107 return arg_1 - arg_2;
00108 }
00109
00110 static mmx_floating
00111 GLUE_19 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00112 return arg_1 * arg_2;
00113 }
00114
00115 static mmx_floating
00116 GLUE_20 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00117 return arg_1 / arg_2;
00118 }
00119
00120 static mmx_floating
00121 GLUE_21 (const mmx_floating &arg_1) {
00122 return sqrt (arg_1);
00123 }
00124
00125 static mmx_floating
00126 GLUE_22 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00127 return pow (arg_1, arg_2);
00128 }
00129
00130 static mmx_floating
00131 GLUE_23 (const mmx_floating &arg_1) {
00132 return exp (arg_1);
00133 }
00134
00135 static mmx_floating
00136 GLUE_24 (const mmx_floating &arg_1) {
00137 return log (arg_1);
00138 }
00139
00140 static mmx_floating
00141 GLUE_25 (const mmx_floating &arg_1) {
00142 return cos (arg_1);
00143 }
00144
00145 static mmx_floating
00146 GLUE_26 (const mmx_floating &arg_1) {
00147 return sin (arg_1);
00148 }
00149
00150 static mmx_floating
00151 GLUE_27 (const mmx_floating &arg_1) {
00152 return tan (arg_1);
00153 }
00154
00155 static mmx_floating
00156 GLUE_28 (const mmx_floating &arg_1) {
00157 return acos (arg_1);
00158 }
00159
00160 static mmx_floating
00161 GLUE_29 (const mmx_floating &arg_1) {
00162 return asin (arg_1);
00163 }
00164
00165 static mmx_floating
00166 GLUE_30 (const mmx_floating &arg_1) {
00167 return atan (arg_1);
00168 }
00169
00170 static bool
00171 GLUE_31 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00172 return arg_1 < arg_2;
00173 }
00174
00175 static bool
00176 GLUE_32 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00177 return arg_1 <= arg_2;
00178 }
00179
00180 static bool
00181 GLUE_33 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00182 return arg_1 > arg_2;
00183 }
00184
00185 static bool
00186 GLUE_34 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00187 return arg_1 >= arg_2;
00188 }
00189
00190 static int
00191 GLUE_35 (const mmx_floating &arg_1) {
00192 return sign (arg_1);
00193 }
00194
00195 static mmx_floating
00196 GLUE_36 (const mmx_floating &arg_1) {
00197 return abs (arg_1);
00198 }
00199
00200 static mmx_floating
00201 GLUE_37 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00202 return min (arg_1, arg_2);
00203 }
00204
00205 static mmx_floating
00206 GLUE_38 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00207 return max (arg_1, arg_2);
00208 }
00209
00210 static mmx_floating
00211 GLUE_39 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00212 return min (arg_1, arg_2);
00213 }
00214
00215 static mmx_floating
00216 GLUE_40 (const mmx_floating &arg_1, const mmx_floating &arg_2) {
00217 return max (arg_1, arg_2);
00218 }
00219
00220 static mmx_floating
00221 GLUE_41 (const mmx_floating &arg_1) {
00222 return floor (arg_1);
00223 }
00224
00225 static mmx_floating
00226 GLUE_42 (const mmx_floating &arg_1) {
00227 return ceil (arg_1);
00228 }
00229
00230 static mmx_floating
00231 GLUE_43 (const mmx_floating &arg_1) {
00232 return trunc (arg_1);
00233 }
00234
00235 static mmx_floating
00236 GLUE_44 (const mmx_floating &arg_1) {
00237 return round (arg_1);
00238 }
00239
00240 static bool
00241 GLUE_45 (const mmx_floating &arg_1) {
00242 return is_finite (arg_1);
00243 }
00244
00245 static bool
00246 GLUE_46 (const mmx_floating &arg_1) {
00247 return is_infinite (arg_1);
00248 }
00249
00250 static bool
00251 GLUE_47 (const mmx_floating &arg_1) {
00252 return is_nan (arg_1);
00253 }
00254
00255 static mmx_floating
00256 GLUE_48 (const mmx_floating &arg_1) {
00257 return times_infinity (arg_1);
00258 }
00259
00260 static int
00261 GLUE_49 (const mmx_floating &arg_1) {
00262 return precision (arg_1);
00263 }
00264
00265 static mmx_floating
00266 GLUE_50 (const mmx_floating &arg_1, const int &arg_2) {
00267 return change_precision (arg_1, arg_2);
00268 }
00269
00270 static mmx_floating
00271 GLUE_51 (const mmx_floating &arg_1) {
00272 return next_above (arg_1);
00273 }
00274
00275 static mmx_floating
00276 GLUE_52 (const mmx_floating &arg_1) {
00277 return next_below (arg_1);
00278 }
00279
00280 static int
00281 GLUE_53 (const mmx_floating &arg_1) {
00282 return exponent (arg_1);
00283 }
00284
00285 static double
00286 GLUE_54 (const mmx_floating &arg_1) {
00287 return magnitude (arg_1);
00288 }
00289
00290 static mmx_floating
00291 GLUE_55 (const mmx_floating &arg_1, const int &arg_2) {
00292 return incexp2 (arg_1, arg_2);
00293 }
00294
00295 static mmx_floating
00296 GLUE_56 (const mmx_floating &arg_1, const int &arg_2) {
00297 return decexp2 (arg_1, arg_2);
00298 }
00299
00300 static mmx_floating
00301 GLUE_57 (const mmx_floating &arg_1) {
00302 return rounding_error (arg_1);
00303 }
00304
00305 static mmx_floating
00306 GLUE_58 (const mmx_floating &arg_1) {
00307 return additive_error (arg_1);
00308 }
00309
00310 static mmx_floating
00311 GLUE_59 (const mmx_floating &arg_1) {
00312 return multiplicative_error (arg_1);
00313 }
00314
00315 static mmx_floating
00316 GLUE_60 (const mmx_floating &arg_1) {
00317 return elementary_error (arg_1);
00318 }
00319
00320 void
00321 glue_floating () {
00322 static bool done = false;
00323 if (done) return;
00324 done = true;
00325 call_glue (string ("glue_rational"));
00326 static alias<int> mmx_significant_digits_alias = global_alias (((int&) mmx_significant_digits));
00327 define_constant<alias<int> > ("significant_digits", mmx_significant_digits_alias);
00328 static alias<int> mmx_bit_precision_alias = global_alias (((int&) mmx_bit_precision));
00329 define_constant<alias<int> > ("bit_precision", mmx_bit_precision_alias);
00330 static alias<int> mmx_discrepancy_alias = global_alias (((int&) mmx_discrepancy));
00331 define_constant<alias<int> > ("discrepancy", mmx_discrepancy_alias);
00332 static alias<bool> mmx_pretty_exponents_alias = global_alias (((bool&) mmx_pretty_exponents));
00333 define_constant<alias<bool> > ("pretty_exponents", mmx_pretty_exponents_alias);
00334 define_type<mmx_floating > (lit ("Floating"));
00335 define ("literal_floating", GLUE_1);
00336 define_converter ("upgrade", GLUE_2, PENALTY_INCLUSION);
00337 define_converter ("upgrade", GLUE_3, PENALTY_INCLUSION);
00338 define_converter ("upgrade", GLUE_4, PENALTY_INCLUSION);
00339 define ("as_floating", GLUE_5);
00340 define ("as_floating", GLUE_6);
00341 define ("as_floating", GLUE_7);
00342 define ("as_floating", GLUE_8);
00343 define ("as_floating", GLUE_9);
00344 define ("as_int", GLUE_10);
00345 define ("as_double", GLUE_11);
00346 define ("as_integer", GLUE_12);
00347 define ("as_string", GLUE_13);
00348 define ("uniform_deviate", GLUE_14);
00349 define ("-", GLUE_15);
00350 define ("square", GLUE_16);
00351 define ("+", GLUE_17);
00352 define ("-", GLUE_18);
00353 define ("*", GLUE_19);
00354 define ("/", GLUE_20);
00355 define ("sqrt", GLUE_21);
00356 define ("^", GLUE_22);
00357 define ("exp", GLUE_23);
00358 define ("log", GLUE_24);
00359 define ("cos", GLUE_25);
00360 define ("sin", GLUE_26);
00361 define ("tan", GLUE_27);
00362 define ("arccos", GLUE_28);
00363 define ("arcsin", GLUE_29);
00364 define ("arctan", GLUE_30);
00365 define ("<", GLUE_31);
00366 define ("<=", GLUE_32);
00367 define (">", GLUE_33);
00368 define (">=", GLUE_34);
00369 define ("sign", GLUE_35);
00370 define ("abs", GLUE_36);
00371 define ("min", GLUE_37);
00372 define ("max", GLUE_38);
00373 define ("inf", GLUE_39);
00374 define ("sup", GLUE_40);
00375 define ("floor", GLUE_41);
00376 define ("ceil", GLUE_42);
00377 define ("trunc", GLUE_43);
00378 define ("round", GLUE_44);
00379 define ("finite?", GLUE_45);
00380 define ("infinite?", GLUE_46);
00381 define ("nan?", GLUE_47);
00382 define ("times_infinity", GLUE_48);
00383 define ("precision", GLUE_49);
00384 define ("change_precision", GLUE_50);
00385 define ("next_above", GLUE_51);
00386 define ("next_below", GLUE_52);
00387 define ("exponent", GLUE_53);
00388 define ("magnitude", GLUE_54);
00389 define ("increase_exponent", GLUE_55);
00390 define ("decrease_exponent", GLUE_56);
00391 define ("rounding_error", GLUE_57);
00392 define ("additive_error", GLUE_58);
00393 define ("multiplicative_error", GLUE_59);
00394 define ("elementary_error", GLUE_60);
00395 }
00396 }