plll  1.0
arithmetic-expressions.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011-2014 University of Zurich
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef PLLL_INCLUDE_GUARD__ARITHMETIC_EXPRESSIONS_HPP
24 #define PLLL_INCLUDE_GUARD__ARITHMETIC_EXPRESSIONS_HPP
25 
26 #include <plll/arithmetic.hpp>
27 
36 namespace plll
37 {
38  namespace arithmetic
39  {
62  namespace expressions
63  {
69 
70  template<typename Context_>
71  class Wrapper
77  {
78  private:
79  const typename Context_::Type & d_value;
80 
81  public:
82  enum { has_evaluate = true, has_context = false };
83  typedef const typename Context_::Type & evaluate_type;
84  typedef Context_ Context;
85 
86  inline Wrapper(const typename Context_::Type & value)
90  : d_value(value)
91  {
92  }
93 
94  inline unsigned long precision() const
100  {
101  return d_value.precision();
102  }
103 
104  inline operator const typename Context_::Type & () const
110  {
111  return d_value;
112  }
113 
114  inline void assignTo(typename Context_::Type & x) const
120  {
121  x = d_value;
122  }
123 
124  inline const typename Context_::Type & evaluate() const
130  {
131  return d_value;
132  }
133  };
134 
135  template<class Context, class Data>
136  class NoneOp
140  {
141  public:
142  enum { has_evaluate = Data::has_evaluate, has_context = Data::has_context };
143  typedef typename Data::evaluate_type evaluate_type;
144 
145  static inline unsigned long precision(const Data & a)
146  {
147  return a.precision();
148  }
149 
150  static inline const Context & context(const Data & a)
151  {
152  return a.context();
153  }
154 
155  static inline void assignTo(typename Context::Type & x, const Data & a)
156  {
157  a.assignTo(x);
158  }
159 
160  static inline evaluate_type evaluate(const Data & a)
161  {
162  return a.evaluate();
163  }
164  };
165 
166  struct NoData
170  {
171  };
172 
178 
179  template<typename Context, typename Data>
180  class NegOp
184  {
185  public:
186  enum { has_evaluate = false, has_context = false };
187 
188  static inline unsigned long precision(const Data & a)
189  {
190  return a.precision();
191  }
192 
193  static inline void assignTo(typename Context::Type & x, const Data & a)
194  {
195  neg(x, a.evaluate());
196  }
197  };
198 
199  template<typename Context, typename Data>
200  class AddOp
204  {
205  public:
206  enum { has_evaluate = false, has_context = false };
207 
208  static inline unsigned long precision(const Data & d)
209  {
210  return std::max(d.first.precision(), d.second.precision());
211  }
212 
213  static inline void assignTo(typename Context::Type & x, const Data & d)
214  {
215  add(x, d.first.evaluate(), d.second.evaluate());
216  }
217  };
218 
219  template<typename Context, typename Data>
220  class SubOp
224  {
225  public:
226  enum { has_evaluate = false, has_context = false };
227 
228  static inline unsigned long precision(const Data & d)
229  {
230  return std::max(d.first.precision(), d.second.precision());
231  }
232 
233  static inline void assignTo(typename Context::Type & x, const Data & d)
234  {
235  sub(x, d.first.evaluate(), d.second.evaluate());
236  }
237  };
238 
239  template<typename Context, typename Data>
240  class MulOp
244  {
245  public:
246  enum { has_evaluate = false, has_context = false };
247 
248  static inline unsigned long precision(const Data & d)
249  {
250  return std::max(d.first.precision(), d.second.precision());
251  }
252 
253  static inline void assignTo(typename Context::Type & x, const Data & d)
254  {
255  mul(x, d.first.evaluate(), d.second.evaluate());
256  }
257  };
258 
259  template<typename Context, typename Data>
260  class DivOp
264  {
265  public:
266  enum { has_evaluate = false, has_context = false };
267 
268  static inline unsigned long precision(const Data & d)
269  {
270  return std::max(d.first.precision(), d.second.precision());
271  }
272 
273  static inline void assignTo(typename Context::Type & x, const Data & d)
274  {
275  div(x, d.first.evaluate(), d.second.evaluate());
276  }
277  };
278 
279  template<typename Context, typename Data>
280  class ModOp
284  {
285  public:
286  enum { has_evaluate = false, has_context = false };
287 
288  static inline unsigned long precision(const Data & d)
289  {
290  return std::max(d.first.precision(), d.second.precision());
291  }
292 
293  static inline void assignTo(typename Context::Type & x, const Data & d)
294  {
295  mod(x, d.first.evaluate(), d.second.evaluate());
296  }
297  };
298 
299  template<typename Context, typename Data>
300  class ShLOp
304  {
305  public:
306  enum { has_evaluate = false, has_context = false };
307 
308  static inline unsigned long precision(const Data & d)
309  {
310  return std::max(d.first.precision(), d.second.precision());
311  }
312 
313  static inline void assignTo(typename Context::Type & x, const Data & d)
314  {
315  shl(x, d.first.evaluate(), d.second.evaluate());
316  }
317  };
318 
319  template<typename Context, typename Data>
320  class ShROp
324  {
325  public:
326  enum { has_evaluate = false, has_context = false };
327 
328  static inline unsigned long precision(const Data & d)
329  {
330  return std::max(d.first.precision(), d.second.precision());
331  }
332 
333  static inline void assignTo(typename Context::Type & x, const Data & d)
334  {
335  shr(x, d.first.evaluate(), d.second.evaluate());
336  }
337  };
338 
339  template<typename Context, typename Data>
340  class ShiftCOp
346  {
347  private:
348  signed long d_v;
349 
350  public:
351  enum { has_evaluate = false, has_context = false };
352 
353  signed long shift() const
354  {
355  return d_v;
356  }
357 
358  inline ShiftCOp(signed long v)
359  : d_v(v)
360  {
361  }
362 
363  static inline unsigned long precision(const Data & a)
364  {
365  return a.precision();
366  }
367 
368  inline void assignTo(typename Context::Type & x, const Data & a) const
369  {
370  shl(x, a.evaluate(), d_v);
371  }
372  };
373 
374  template<typename Context, typename Data>
375  class AndOp
379  {
380  public:
381  enum { has_evaluate = false, has_context = false };
382 
383  static inline unsigned long precision(const Data & d)
384  {
385  return std::max(d.first.precision(), d.second.precision());
386  }
387 
388  static inline void assignTo(typename Context::Type & x, const Data & d)
389  {
390  band(x, d.first.evaluate(), d.second.evaluate());
391  }
392  };
393 
394  template<typename Context, typename Data>
395  class OrOp
399  {
400  public:
401  enum { has_evaluate = false, has_context = false };
402 
403  static inline unsigned long precision(const Data & d)
404  {
405  return std::max(d.first.precision(), d.second.precision());
406  }
407 
408  static inline void assignTo(typename Context::Type & x, const Data & d)
409  {
410  bor(x, d.first.evaluate(), d.second.evaluate());
411  }
412  };
413 
414  template<typename Context, typename Data>
415  class XOROp
419  {
420  public:
421  enum { has_evaluate = false, has_context = false };
422 
423  static inline unsigned long precision(const Data & d)
424  {
425  return std::max(d.first.precision(), d.second.precision());
426  }
427 
428  static inline void assignTo(typename Context::Type & x, const Data & d)
429  {
430  bxor(x, d.first.evaluate(), d.second.evaluate());
431  }
432  };
433 
434  template<typename Context, typename Data>
435  class BitInvOp
439  {
440  public:
441  enum { has_evaluate = false, has_context = false };
442 
443  static inline unsigned long precision(const Data & d)
444  {
445  return d.precision();
446  }
447 
448  static inline void assignTo(typename Context::Type & x, const Data & d)
449  {
450  bneg(x, d.evaluate());
451  }
452  };
453 
459 
460  template<typename Context, typename Data>
465  {
466  public:
467  enum { has_evaluate = false, has_context = false };
468 
469  static inline unsigned long precision(const Data & d)
470  {
471  return d.precision();
472  }
473 
474  static inline void assignTo(typename Context::Type & x, const Data & d)
475  {
476  sqrtFloor(x, d.evaluate());
477  }
478  };
479 
480  template<typename Context, typename Data>
485  {
486  public:
487  enum { has_evaluate = false, has_context = false };
488 
489  static inline unsigned long precision(const Data & d)
490  {
491  return d.precision();
492  }
493 
494  static inline void assignTo(typename Context::Type & x, const Data & d)
495  {
496  sqrtCeil(x, d.evaluate());
497  }
498  };
499 
500  template<class Context, class Data>
501  class GCDOp
505  {
506  public:
507  enum { has_evaluate = false, has_context = false };
508 
509  static inline unsigned long precision(const Data & d)
510  {
511  return std::max(d.first.precision(), d.second.precision());
512  }
513 
514  static inline void assignTo(typename Context::Type & x, const Data & d)
515  {
516  GCD(x, d.first.evaluate(), d.second.evaluate());
517  }
518  };
519 
520  template<class Context, class Data>
521  class LCMOp
525  {
526  public:
527  enum { has_evaluate = false, has_context = false };
528 
529  static inline unsigned long precision(const Data & d)
530  {
531  return std::max(d.first.precision(), d.second.precision());
532  }
533 
534  static inline void assignTo(typename Context::Type & x, const Data & d)
535  {
536  LCM(x, d.first.evaluate(), d.second.evaluate());
537  }
538  };
539 
540  template<class Context, class Data>
545  {
546  public:
547  enum { has_evaluate = false, has_context = false };
548 
549  static inline unsigned long precision(const Data & d)
550  {
551  return std::max(d.first.precision(), d.second.precision());
552  }
553 
554  static inline void assignTo(typename Context::Type & x, const Data & d)
555  {
556  floorDiv(x, d.first.evaluate(), d.second.evaluate());
557  }
558  };
559 
560  template<class Context, class Data>
561  class CeilDivOp
565  {
566  public:
567  enum { has_evaluate = false, has_context = false };
568 
569  static inline unsigned long precision(const Data & d)
570  {
571  return std::max(d.first.precision(), d.second.precision());
572  }
573 
574  static inline void assignTo(typename Context::Type & x, const Data & d)
575  {
576  ceilDiv(x, d.first.evaluate(), d.second.evaluate());
577  }
578  };
579 
580  template<class Context, class Data>
585  {
586  public:
587  enum { has_evaluate = false, has_context = false };
588 
589  static inline unsigned long precision(const Data & d)
590  {
591  return std::max(d.first.precision(), d.second.precision());
592  }
593 
594  static inline void assignTo(typename Context::Type & x, const Data & d)
595  {
596  roundDiv(x, d.first.evaluate(), d.second.evaluate());
597  }
598  };
599 
600  template<typename Context, typename Data>
601  class AbsOp
605  {
606  public:
607  enum { has_evaluate = false, has_context = false };
608 
609  static inline unsigned long precision(const Data & a)
610  {
611  return a.precision();
612  }
613 
614  static inline void assignTo(typename Context::Type & x, const Data & a)
615  {
616  abs(x, a.evaluate());
617  }
618  };
619 
620  template<typename Context, typename Data>
621  class SquareOp
625  {
626  public:
627  enum { has_evaluate = false, has_context = false };
628 
629  static inline unsigned long precision(const Data & a)
630  {
631  return a.precision();
632  }
633 
634  static inline void assignTo(typename Context::Type & x, const Data & a)
635  {
636  square(x, a.evaluate());
637  }
638  };
639 
640  template<class Context, class Data>
641  class SinOp
645  {
646  public:
647  enum { has_evaluate = false, has_context = false };
648 
649  static inline unsigned long precision(const Data & a)
650  {
651  return a.precision();
652  }
653 
654  static inline void assignTo(typename Context::Type & x, const Data & a)
655  {
656  sin(x, a.evaluate());
657  }
658  };
659 
660  template<class Context, class Data>
661  class CosOp
665  {
666  public:
667  enum { has_evaluate = false, has_context = false };
668 
669  static inline unsigned long precision(const Data & a)
670  {
671  return a.precision();
672  }
673 
674  static inline void assignTo(typename Context::Type & x, const Data & a)
675  {
676  cos(x, a.evaluate());
677  }
678  };
679 
680  template<class Context, class Data>
681  class TanOp
685  {
686  public:
687  enum { has_evaluate = false, has_context = false };
688 
689  static inline unsigned long precision(const Data & a)
690  {
691  return a.precision();
692  }
693 
694  static inline void assignTo(typename Context::Type & x, const Data & a)
695  {
696  tan(x, a.evaluate());
697  }
698  };
699 
700  template<class Context, class Data>
701  class ASinOp
705  {
706  public:
707  enum { has_evaluate = false, has_context = false };
708 
709  static inline unsigned long precision(const Data & a)
710  {
711  return a.precision();
712  }
713 
714  static inline void assignTo(typename Context::Type & x, const Data & a)
715  {
716  asin(x, a.evaluate());
717  }
718  };
719 
720  template<class Context, class Data>
721  class ACosOp
725  {
726  public:
727  enum { has_evaluate = false, has_context = false };
728 
729  static inline unsigned long precision(const Data & a)
730  {
731  return a.precision();
732  }
733 
734  static inline void assignTo(typename Context::Type & x, const Data & a)
735  {
736  acos(x, a.evaluate());
737  }
738  };
739 
740  template<class Context, class Data>
741  class ATanOp
745  {
746  public:
747  enum { has_evaluate = false, has_context = false };
748 
749  static inline unsigned long precision(const Data & a)
750  {
751  return a.precision();
752  }
753 
754  static inline void assignTo(typename Context::Type & x, const Data & a)
755  {
756  atan(x, a.evaluate());
757  }
758  };
759 
760  template<class Context, class Data>
761  class ATan2Op
765  {
766  public:
767  enum { has_evaluate = false, has_context = false };
768 
769  static inline unsigned long precision(const Data & d)
770  {
771  return std::max(d.first.precision(), d.second.precision());
772  }
773 
774  static inline void assignTo(typename Context::Type & x, const Data & d)
775  {
776  atan2(x, d.first.evaluate(), d.second.evaluate());
777  }
778  };
779 
780  template<class Context, class Data>
781  class ExpOp
785  {
786  public:
787  enum { has_evaluate = false, has_context = false };
788 
789  static inline unsigned long precision(const Data & a)
790  {
791  return a.precision();
792  }
793 
794  static inline void assignTo(typename Context::Type & x, const Data & a)
795  {
796  exp(x, a.evaluate());
797  }
798  };
799 
800  template<class Context, class Data>
801  class LogOp
805  {
806  public:
807  enum { has_evaluate = false, has_context = false };
808 
809  static inline unsigned long precision(const Data & a)
810  {
811  return a.precision();
812  }
813 
814  static inline void assignTo(typename Context::Type & x, const Data & a)
815  {
816  log(x, a.evaluate());
817  }
818  };
819 
820  template<class Context, class Data>
821  class Log2Op
825  {
826  public:
827  enum { has_evaluate = false, has_context = false };
828 
829  static inline unsigned long precision(const Data & a)
830  {
831  return a.precision();
832  }
833 
834  static inline void assignTo(typename Context::Type & x, const Data & a)
835  {
836  log2(x, a.evaluate());
837  }
838  };
839 
840  template<class Context, class Data>
841  class Log10Op
845  {
846  public:
847  enum { has_evaluate = false, has_context = false };
848 
849  static inline unsigned long precision(const Data & a)
850  {
851  return a.precision();
852  }
853 
854  static inline void assignTo(typename Context::Type & x, const Data & a)
855  {
856  log10(x, a.evaluate());
857  }
858  };
859 
860  template<class Context, class Data>
861  class SqrtOp
865  {
866  public:
867  enum { has_evaluate = false, has_context = false };
868 
869  static inline unsigned long precision(const Data & a)
870  {
871  return a.precision();
872  }
873 
874  static inline void assignTo(typename Context::Type & x, const Data & a)
875  {
876  sqrt(x, a.evaluate());
877  }
878  };
879 
880  template<class Context, class Data>
881  class GammaOp
885  {
886  public:
887  enum { has_evaluate = false, has_context = false };
888 
889  static inline unsigned long precision(const Data & a)
890  {
891  return a.precision();
892  }
893 
894  static inline void assignTo(typename Context::Type & x, const Data & a)
895  {
896  gamma(x, a.evaluate());
897  }
898  };
899 
900  template<class Context, class Data>
901  class LGammaOp
906  {
907  public:
908  enum { has_evaluate = false, has_context = false };
909 
910  static inline unsigned long precision(const Data & a)
911  {
912  return a.precision();
913  }
914 
915  static inline void assignTo(typename Context::Type & x, const Data & a)
916  {
917  lgamma(x, a.evaluate());
918  }
919  };
920 
921  template<class Context, class Data>
922  class LGamma2Op
927  {
928  private:
929  int & d_sign;
930 
931  public:
932  enum { has_evaluate = false, has_context = false };
933 
934  inline LGamma2Op(int & sign)
935  : d_sign(sign)
936  {
937  }
938 
939  static inline unsigned long precision(const Data & a)
940  {
941  return a.precision();
942  }
943 
944  inline void assignTo(typename Context::Type & x, const Data & a) const
945  {
946  lgamma(x, d_sign, a.evaluate());
947  }
948  };
949 
950  template<typename Type>
951  struct PowerCOp
958  {
959  template<class Context, class Data>
960  class impl
964  {
965  private:
966  Type d_v;
967 
968  public:
969  enum { has_evaluate = false, has_context = false };
970 
971  inline impl(Type v)
972  : d_v(v)
973  {
974  }
975 
976  static inline unsigned long precision(const Data & a)
977  {
978  return a.precision();
979  }
980 
981  inline void assignTo(typename Context::Type & x, const Data & a) const
982  {
983  power(x, a.evaluate(), d_v);
984  }
985  };
986  };
987 
988  template<class Context, class Data>
989  class PowerOp
993  {
994  public:
995  enum { has_evaluate = false, has_context = false };
996 
997  static inline unsigned long precision(const Data & d)
998  {
999  return d.first.precision();
1000  }
1001 
1002  static inline void assignTo(typename Context::Type & x, const Data & d)
1003  {
1004  power(x, d.first.evaluate(), d.second.evaluate());
1005  }
1006  };
1007 
1013 
1014  template<typename Context, typename Data>
1020  {
1021  private:
1022  const Context & d_context;
1023 
1024  public:
1025  enum { has_evaluate = false, has_context = true };
1026 
1027  inline AbsOp_Context(const Context & context)
1028  : d_context(context)
1029  {
1030  }
1031 
1032  inline unsigned long precision(const Data & a)
1033  {
1034  return d_context.getRealPrecision();
1035  }
1036 
1037  static inline void assignTo(typename Context::Type & x, const Data & a)
1038  {
1039  abs(x, a.evaluate());
1040  }
1041  };
1042 
1043  template<typename Context, typename Data>
1048  {
1049  private:
1050  const Context & d_context;
1051 
1052  public:
1053  enum { has_evaluate = false, has_context = true };
1054 
1055  inline SquareOp_Context(const Context & context)
1056  : d_context(context)
1057  {
1058  }
1059 
1060  inline unsigned long precision(const Data & a)
1061  {
1062  return d_context.getRealPrecision();
1063  }
1064 
1065  static inline void assignTo(typename Context::Type & x, const Data & a)
1066  {
1067  square(x, a.evaluate());
1068  }
1069  };
1070 
1071  template<class Context, class Data>
1076  {
1077  private:
1078  const Context & d_context;
1079 
1080  public:
1081  enum { has_evaluate = false, has_context = true };
1082 
1083  inline SinOp_Context(const Context & context)
1084  : d_context(context)
1085  {
1086  }
1087 
1088  inline unsigned long precision(const Data & a)
1089  {
1090  return d_context.getRealPrecision();
1091  }
1092 
1093  static inline void assignTo(typename Context::Type & x, const Data & a)
1094  {
1095  sin(x, a.evaluate());
1096  }
1097  };
1098 
1099  template<class Context, class Data>
1104  {
1105  private:
1106  const Context & d_context;
1107 
1108  public:
1109  enum { has_evaluate = false, has_context = true };
1110 
1111  inline CosOp_Context(const Context & context)
1112  : d_context(context)
1113  {
1114  }
1115 
1116  inline unsigned long precision(const Data & a)
1117  {
1118  return d_context.getRealPrecision();
1119  }
1120 
1121  static inline void assignTo(typename Context::Type & x, const Data & a)
1122  {
1123  cos(x, a.evaluate());
1124  }
1125  };
1126 
1127  template<class Context, class Data>
1132  {
1133  private:
1134  const Context & d_context;
1135 
1136  public:
1137  enum { has_evaluate = false, has_context = true };
1138 
1139  inline TanOp_Context(const Context & context)
1140  : d_context(context)
1141  {
1142  }
1143 
1144  inline unsigned long precision(const Data & a)
1145  {
1146  return d_context.getRealPrecision();
1147  }
1148 
1149  static inline void assignTo(typename Context::Type & x, const Data & a)
1150  {
1151  tan(x, a.evaluate());
1152  }
1153  };
1154 
1155  template<class Context, class Data>
1161  {
1162  private:
1163  const Context & d_context;
1164 
1165  public:
1166  enum { has_evaluate = false, has_context = true };
1167 
1168  inline ASinOp_Context(const Context & context)
1169  : d_context(context)
1170  {
1171  }
1172 
1173  inline unsigned long precision(const Data & a)
1174  {
1175  return d_context.getRealPrecision();
1176  }
1177 
1178  static inline void assignTo(typename Context::Type & x, const Data & a)
1179  {
1180  asin(x, a.evaluate());
1181  }
1182  };
1183 
1184  template<class Context, class Data>
1190  {
1191  private:
1192  const Context & d_context;
1193 
1194  public:
1195  enum { has_evaluate = false, has_context = true };
1196 
1197  inline ACosOp_Context(const Context & context)
1198  : d_context(context)
1199  {
1200  }
1201 
1202  inline unsigned long precision(const Data & a)
1203  {
1204  return d_context.getRealPrecision();
1205  }
1206 
1207  static inline void assignTo(typename Context::Type & x, const Data & a)
1208  {
1209  acos(x, a.evaluate());
1210  }
1211  };
1212 
1213  template<class Context, class Data>
1219  {
1220  private:
1221  const Context & d_context;
1222 
1223  public:
1224  enum { has_evaluate = false, has_context = true };
1225 
1226  inline ATanOp_Context(const Context & context)
1227  : d_context(context)
1228  {
1229  }
1230 
1231  inline unsigned long precision(const Data & a)
1232  {
1233  return d_context.getRealPrecision();
1234  }
1235 
1236  static inline void assignTo(typename Context::Type & x, const Data & a)
1237  {
1238  atan(x, a.evaluate());
1239  }
1240  };
1241 
1242  template<class Context, class Data>
1248  {
1249  private:
1250  const Context & d_context;
1251 
1252  public:
1253  enum { has_evaluate = false, has_context = true };
1254 
1255  inline ATan2Op_Context(const Context & context)
1256  : d_context(context)
1257  {
1258  }
1259 
1260  inline unsigned long precision(const Data & d)
1261  {
1262  return d_context.getRealPrecision();
1263  }
1264 
1265  static inline void assignTo(typename Context::Type & x, const Data & d)
1266  {
1267  atan2(x, d.first.evaluate(), d.second.evaluate());
1268  }
1269  };
1270 
1271  template<class Context, class Data>
1277  {
1278  private:
1279  const Context & d_context;
1280 
1281  public:
1282  enum { has_evaluate = false, has_context = true };
1283 
1284  inline ExpOp_Context(const Context & context)
1285  : d_context(context)
1286  {
1287  }
1288 
1289  inline unsigned long precision(const Data & a)
1290  {
1291  return d_context.getRealPrecision();
1292  }
1293 
1294  static inline void assignTo(typename Context::Type & x, const Data & a)
1295  {
1296  exp(x, a.evaluate());
1297  }
1298  };
1299 
1300  template<class Context, class Data>
1306  {
1307  private:
1308  const Context & d_context;
1309 
1310  public:
1311  enum { has_evaluate = false, has_context = true };
1312 
1313  inline LogOp_Context(const Context & context)
1314  : d_context(context)
1315  {
1316  }
1317 
1318  inline unsigned long precision(const Data & a)
1319  {
1320  return d_context.getRealPrecision();
1321  }
1322 
1323  static inline void assignTo(typename Context::Type & x, const Data & a)
1324  {
1325  log(x, a.evaluate());
1326  }
1327  };
1328 
1329  template<class Context, class Data>
1335  {
1336  private:
1337  const Context & d_context;
1338 
1339  public:
1340  enum { has_evaluate = false, has_context = true };
1341 
1342  inline Log2Op_Context(const Context & context)
1343  : d_context(context)
1344  {
1345  }
1346 
1347  inline unsigned long precision(const Data & a)
1348  {
1349  return d_context.getRealPrecision();
1350  }
1351 
1352  static inline void assignTo(typename Context::Type & x, const Data & a)
1353  {
1354  log2(x, a.evaluate());
1355  }
1356  };
1357 
1358  template<class Context, class Data>
1364  {
1365  private:
1366  const Context & d_context;
1367 
1368  public:
1369  enum { has_evaluate = false, has_context = true };
1370 
1371  inline Log10Op_Context(const Context & context)
1372  : d_context(context)
1373  {
1374  }
1375 
1376  inline unsigned long precision(const Data & a)
1377  {
1378  return d_context.getRealPrecision();
1379  }
1380 
1381  static inline void assignTo(typename Context::Type & x, const Data & a)
1382  {
1383  log10(x, a.evaluate());
1384  }
1385  };
1386 
1387  template<class Context, class Data>
1393  {
1394  private:
1395  const Context & d_context;
1396 
1397  public:
1398  enum { has_evaluate = false, has_context = true };
1399 
1400  inline SqrtOp_Context(const Context & context)
1401  : d_context(context)
1402  {
1403  }
1404 
1405  inline unsigned long precision(const Data & a)
1406  {
1407  return d_context.getRealPrecision();
1408  }
1409 
1410  static inline void assignTo(typename Context::Type & x, const Data & a)
1411  {
1412  sqrt(x, a.evaluate());
1413  }
1414  };
1415 
1416  template<class Context, class Data>
1422  {
1423  private:
1424  const Context & d_context;
1425 
1426  public:
1427  enum { has_evaluate = false, has_context = true };
1428 
1429  inline GammaOp_Context(const Context & context)
1430  : d_context(context)
1431  {
1432  }
1433 
1434  inline unsigned long precision(const Data & a)
1435  {
1436  return d_context.getRealPrecision();
1437  }
1438 
1439  static inline void assignTo(typename Context::Type & x, const Data & a)
1440  {
1441  gamma(x, a.evaluate());
1442  }
1443  };
1444 
1445  template<class Context, class Data>
1451  {
1452  private:
1453  const Context & d_context;
1454 
1455  public:
1456  enum { has_evaluate = false, has_context = true };
1457 
1458  inline LGammaOp_Context(const Context & context)
1459  : d_context(context)
1460  {
1461  }
1462 
1463  inline unsigned long precision(const Data & a)
1464  {
1465  return d_context.getRealPrecision();
1466  }
1467 
1468  static inline void assignTo(typename Context::Type & x, const Data & a)
1469  {
1470  lgamma(x, a.evaluate());
1471  }
1472  };
1473 
1474  template<class Context, class Data>
1481  {
1482  private:
1483  const Context & d_context;
1484  int & d_sign;
1485 
1486  public:
1487  enum { has_evaluate = false, has_context = true };
1488 
1489  inline LGamma2Op_Context(int & sign, const Context & context)
1490  : d_context(context), d_sign(sign)
1491  {
1492  }
1493 
1494  inline unsigned long precision(const Data & a)
1495  {
1496  return d_context.getRealPrecision();
1497  }
1498 
1499  inline void assignTo(typename Context::Type & x, const Data & a) const
1500  {
1501  lgamma(x, d_sign, a.evaluate());
1502  }
1503  };
1504 
1505  template<typename Type>
1514  {
1515  template<class Context, class Data>
1516  class impl
1520  {
1521  private:
1522  const Context & d_context;
1523  Type d_v;
1524 
1525  public:
1526  enum { has_evaluate = false, has_context = true };
1527 
1528  inline impl(Type v, const Context & context)
1529  : d_context(context), d_v(v)
1530  {
1531  }
1532 
1533  inline unsigned long precision(const Data & a)
1534  {
1535  return d_context.getRealPrecision();
1536  }
1537 
1538  inline void assignTo(typename Context::Type & x, const Data & a) const
1539  {
1540  power(x, a.evaluate(), d_v);
1541  }
1542  };
1543  };
1544 
1545  template<class Context, class Data>
1551  {
1552  private:
1553  const Context & d_context;
1554 
1555  public:
1556  enum { has_evaluate = false, has_context = true };
1557 
1558  inline PowerOp_Context(const Context & context)
1559  : d_context(context)
1560  {
1561  }
1562 
1563  inline unsigned long precision(const Data & d)
1564  {
1565  return d.first.precision();
1566  }
1567 
1568  static inline void assignTo(typename Context::Type & x, const Data & d)
1569  {
1570  power(x, d.first.evaluate(), d.second.evaluate());
1571  }
1572  };
1573 
1579 
1580  template<typename Type>
1587  {
1588  private:
1589  Type d_value;
1590 
1591  public:
1592  inline ConversionWrapper(const Type & value)
1593  : d_value(value)
1594  {
1595  }
1596 
1597  inline const Type & evaluate() const
1598  {
1599  return d_value;
1600  }
1601  };
1602 
1603  template<typename Context, typename Data>
1609  {
1610  private:
1611  const Context & d_context;
1612 
1613  public:
1614  enum { has_evaluate = false, has_context = true };
1615 
1616  inline ConvertOp_Context(const Context & context)
1617  : d_context(context)
1618  {
1619  }
1620 
1621  const Context & context(const Data &) const
1622  {
1623  return d_context;
1624  }
1625 
1626  inline unsigned long precision(const Data & a) const
1627  {
1628  return d_context.getRealPrecision();
1629  }
1630 
1631  inline void assignTo(typename Context::Type & x, const Data & a) const
1632  {
1633  convert(x, a.evaluate(), d_context);
1634  }
1635  };
1636 
1637  template<typename Context, typename Data>
1643  {
1644  private:
1645  const Context & d_context;
1646 
1647  public:
1648  enum { has_evaluate = false, has_context = true };
1649 
1650  inline ConvertFloorOp_Context(const Context & context)
1651  : d_context(context)
1652  {
1653  }
1654 
1655  const Context & context(const Data &) const
1656  {
1657  return d_context;
1658  }
1659 
1660  inline unsigned long precision(const Data & a) const
1661  {
1662  return d_context.getRealPrecision();
1663  }
1664 
1665  inline void assignTo(typename Context::Type & x, const Data & a) const
1666  {
1667  convert_floor(x, a.evaluate(), d_context);
1668  }
1669  };
1670 
1671  template<typename Context, typename Data>
1677  {
1678  private:
1679  const Context & d_context;
1680 
1681  public:
1682  enum { has_evaluate = false, has_context = true };
1683 
1684  inline ConvertRoundOp_Context(const Context & context)
1685  : d_context(context)
1686  {
1687  }
1688 
1689  const Context & context(const Data &) const
1690  {
1691  return d_context;
1692  }
1693 
1694  inline unsigned long precision(const Data & a) const
1695  {
1696  return d_context.getRealPrecision();
1697  }
1698 
1699  inline void assignTo(typename Context::Type & x, const Data & a) const
1700  {
1701  convert_round(x, a.evaluate(), d_context);
1702  }
1703  };
1704 
1705  template<typename Context, typename Data>
1712  {
1713  private:
1714  const Context & d_context;
1715  bool & d_rounded_up;
1716 
1717  public:
1718  enum { has_evaluate = false, has_context = true };
1719 
1720  inline ConvertRound2Op_Context(bool & rounded_up, const Context & context)
1721  : d_context(context), d_rounded_up(rounded_up)
1722  {
1723  }
1724 
1725  const Context & context(const Data &) const
1726  {
1727  return d_context;
1728  }
1729 
1730  inline unsigned long precision(const Data & a) const
1731  {
1732  return d_context.getRealPrecision();
1733  }
1734 
1735  inline void assignTo(typename Context::Type & x, const Data & a) const
1736  {
1737  convert_round(x, a.evaluate(), d_rounded_up, d_context);
1738  }
1739  };
1740 
1741  template<typename Context, typename Data>
1747  {
1748  private:
1749  const Context & d_context;
1750 
1751  public:
1752  enum { has_evaluate = false, has_context = true };
1753 
1754  inline ConvertCeilOp_Context(const Context & context)
1755  : d_context(context)
1756  {
1757  }
1758 
1759  const Context & context(const Data &) const
1760  {
1761  return d_context;
1762  }
1763 
1764  inline unsigned long precision(const Data & a) const
1765  {
1766  return d_context.getRealPrecision();
1767  }
1768 
1769  inline void assignTo(typename Context::Type & x, const Data & a) const
1770  {
1771  convert_ceil(x, a.evaluate(), d_context);
1772  }
1773  };
1774 
1780 
1781  template<typename Context_, class Data, template<typename, typename> class Op>
1782  class Expression : public Op<Context_, Data>
1791  {
1792  private:
1793  Data d_data;
1794 
1795  template<bool, class A, class B>
1796  struct SelectET
1797  {
1798  typedef typename A::evaluate_type result;
1799  };
1800 
1801  template<class A, class B>
1802  struct SelectET<false, A, B>
1803  {
1804  typedef B result;
1805  };
1806 
1807  public:
1808  enum { has_evaluate = true, has_context = Op<Context_, Data>::has_context };
1809  typedef typename SelectET<Op<Context_, Data>::has_evaluate,
1810  Op<Context_, Data>, typename Context_::Type>::result evaluate_type;
1811  typedef Context_ Context;
1812 
1813  inline const Op<Context_, Data> & op() const
1817  {
1818  return *this;
1819  }
1820 
1821  inline const Data & data() const
1825  {
1826  return d_data;
1827  }
1828 
1829  inline const Context & context() const
1834  {
1835  return Op<Context_, Data>::context(d_data);
1836  }
1837 
1838  inline Expression(const Data & data, const Op<Context_, Data> & op)
1842  : Op<Context_, Data>(op), d_data(data)
1843  {
1844  }
1845 
1846  inline Expression(const Data & data)
1851  : Op<Context_, Data>(), d_data(data)
1852  {
1853  }
1854 
1855  inline unsigned long precision() const
1860  {
1861  return Op<Context_, Data>::precision(d_data);
1862  }
1863 
1867  inline void assignTo(typename Context::Type & x) const;
1868 
1869  private:
1870  template<bool b>
1871  inline evaluate_type do_cast(helper::BoolToType<true>, helper::BoolToType<b>) const
1872  {
1873  return Op<Context_, Data>::evaluate(d_data);
1874  }
1875 
1876  inline evaluate_type do_cast(helper::BoolToType<false>, helper::BoolToType<true>) const
1877  {
1878  return typename Context_::Type(*this, Op<Context_, Data>::context(d_data));
1879  }
1880 
1881  inline evaluate_type do_cast(helper::BoolToType<false>, helper::BoolToType<false>) const
1882  {
1883  return typename Context_::Type(*this);
1884  }
1885 
1886  public:
1887  inline operator evaluate_type () const
1891  {
1892  return do_cast(helper::BoolToType<Op<Context_, Data>::has_evaluate>(), helper::BoolToType<has_context>());
1893  }
1894 
1895  inline evaluate_type evaluate() const
1899  {
1900  return do_cast(helper::BoolToType<Op<Context_, Data>::has_evaluate>(), helper::BoolToType<has_context>());
1901  }
1902  };
1903 
1904  template<typename Context, class Data, class Op>
1905  void do_assign(typename Context::Type & x, const Op & op, const Data & data)
1920  {
1921  op.assignTo(x, data);
1922  }
1923 
1924  template<typename Context, class Data, template<typename, typename> class Op>
1925  inline void Expression<Context, Data, Op>::assignTo(typename Context::Type & x) const
1926  {
1927  do_assign<Context, Data, Op<Context, Data> >(x, static_cast<const Op<Context, Data> &>(*this), d_data);
1928  }
1929 
1930  template<typename Context>
1931  inline Expression<Context, Wrapper<Context>, NoneOp> make_expression(const typename Context::Type & a)
1935  {
1937  }
1938  }
1939 
1940  // generic conversion from expressions:
1941  namespace implementation
1942  {
1943  template<class SourceContext, class Data, template<typename, typename> class Op, class Dest>
1944  class conversion_impl<expressions::Expression<SourceContext, Data, Op>, Dest>
1951  {
1952  public:
1959 
1960  static void convert(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1961  {
1963  }
1964 
1965  static RetVal convert(const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1966  {
1968  }
1969 
1970  static void convert_frac(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v1,
1971  const expressions::Expression<SourceContext, Data, Op> & v2, const Dest & c)
1972  {
1974  }
1975 
1976  static RetVal_Frac convert_frac(const expressions::Expression<SourceContext, Data, Op> & v1,
1977  const expressions::Expression<SourceContext, Data, Op> & v2, const Dest & c)
1978  {
1980  }
1981 
1982  static void floor(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1983  {
1985  }
1986 
1987  static RetVal_Floor floor(const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1988  {
1990  }
1991 
1992  static void round(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1993  {
1995  }
1996 
1997  static RetVal_Round round(const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
1998  {
2000  }
2001 
2002  static void round(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v, bool & up, const Dest & c)
2003  {
2005  }
2006 
2007  static RetVal_Round2 round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up, const Dest & c)
2008  {
2010  }
2011 
2012  static void ceil(typename Dest::Type & d, const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
2013  {
2015  }
2016 
2017  static RetVal_Ceil ceil(const expressions::Expression<SourceContext, Data, Op> & v, const Dest & c)
2018  {
2020  }
2021  };
2022 
2023  template<class SourceContext, class Data, template<typename, typename> class Op>
2024  class nativeconversion_impl<expressions::Expression<SourceContext, Data, Op> >
2030  {
2031  public:
2032  static int toInt(const expressions::Expression<SourceContext, Data, Op> & v)
2033  {
2035  }
2036 
2037  static int toInt_Floor(const expressions::Expression<SourceContext, Data, Op> & v)
2038  {
2040  }
2041 
2042  static int toInt_Round(const expressions::Expression<SourceContext, Data, Op> & v)
2043  {
2045  }
2046 
2047  static int toInt_Round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up)
2048  {
2050  }
2051 
2052  static int toInt_Ceil(const expressions::Expression<SourceContext, Data, Op> & v)
2053  {
2055  }
2056 
2057  static unsigned int toUInt(const expressions::Expression<SourceContext, Data, Op> & v)
2058  {
2060  }
2061 
2062  static unsigned int toUInt_Floor(const expressions::Expression<SourceContext, Data, Op> & v)
2063  {
2065  }
2066 
2067  static unsigned int toUInt_Round(const expressions::Expression<SourceContext, Data, Op> & v)
2068  {
2070  }
2071 
2072  static unsigned int toUInt_Round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up)
2073  {
2075  }
2076 
2077  static unsigned int toUInt_Ceil(const expressions::Expression<SourceContext, Data, Op> & v)
2078  {
2080  }
2081 
2082  static long toLong(const expressions::Expression<SourceContext, Data, Op> & v)
2083  {
2085  }
2086 
2087  static long toLong_Floor(const expressions::Expression<SourceContext, Data, Op> & v)
2088  {
2090  }
2091 
2092  static long toLong_Round(const expressions::Expression<SourceContext, Data, Op> & v)
2093  {
2095  }
2096 
2097  static long toLong_Round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up)
2098  {
2100  }
2101 
2102  static long toLong_Ceil(const expressions::Expression<SourceContext, Data, Op> & v)
2103  {
2105  }
2106 
2107  static unsigned long toULong(const expressions::Expression<SourceContext, Data, Op> & v)
2108  {
2110  }
2111 
2112  static unsigned long toULong_Floor(const expressions::Expression<SourceContext, Data, Op> & v)
2113  {
2115  }
2116 
2117  static unsigned long toULong_Round(const expressions::Expression<SourceContext, Data, Op> & v)
2118  {
2120  }
2121 
2122  static unsigned long toULong_Round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up)
2123  {
2125  }
2126 
2127  static unsigned long toULong_Ceil(const expressions::Expression<SourceContext, Data, Op> & v)
2128  {
2130  }
2131 
2132  static long long toLongLong(const expressions::Expression<SourceContext, Data, Op> & v)
2133  {
2135  }
2136 
2137  static long long toLongLong_Floor(const expressions::Expression<SourceContext, Data, Op> & v)
2138  {
2140  }
2141 
2142  static long long toLongLong_Round(const expressions::Expression<SourceContext, Data, Op> & v)
2143  {
2145  }
2146 
2147  static long long toLongLong_Round(const expressions::Expression<SourceContext, Data, Op> & v, bool & up)
2148  {
2150  }
2151 
2152  static long long toLongLong_Ceil(const expressions::Expression<SourceContext, Data, Op> & v)
2153  {
2155  }
2156 
2157  static float toFloat(const expressions::Expression<SourceContext, Data, Op> & v)
2158  {
2160  }
2161 
2162  static double toDouble(const expressions::Expression<SourceContext, Data, Op> & v)
2163  {
2165  }
2166 
2167  static long double toLongDouble(const expressions::Expression<SourceContext, Data, Op> & v)
2168  {
2170  }
2171  };
2172  }
2173  }
2174 }
2175 
2176 #endif
Returns the sum of the operands.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::FloorDivOp > floorDiv(const Integer &a, const Integer &b)
Computes and returns .
Converts the argument to the destination type. Uses the context stored in the operator.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ExpOp > exp(const Real &i)
Returns the exponential function evaluated at the given floating point number.
Returns the rounded quotient of the two operands.
Returns the ceil of the quotient of the two operands.
Simply provides the data without any modifications.
Implementation of raising to a power by a constant exponent.
Returns the ceil of the square root of the operand.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ATanOp > atan(const Real &i)
Returns the arctangent of the given floating point number.
void assignTo(typename Context_::Type &x) const
Assigns the value to the destination variable.
Returns the tangent of the operand.
Returns the floor of the quotient of the two operands.
void shr(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
void bneg(Integer &r, const Integer &a)
Takes the bitwise complement of a and stores the result in r.
Returns the logarithm of the absolute value of the Gamma function evaluated of the operand together w...
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtFloorOp > sqrtFloor(const Integer &i)
Computes and returns the floor of the square root of i.
Returns the tangent of the operand. Uses the context stored in the operator.
Returns the square root of the operand. Uses the context stored in the operator.
Returns the arcus tangent of the operand.
void do_assign(typename Context::Type &x, const Op &op, const Data &data)
Performs the assignment of the expression to x.
Returns the sine of the operand. Uses the context stored in the operator.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::TanOp > tan(const Real &i)
Returns the tangent of the given floating point number.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::GammaOp > gamma(const Real &i)
Returns the Gamma function evaluated at the given floating point number.
Returns the arcus cosine of the operand.
Returns the negative of the operand.
Expression(const Data &data)
Creates an expression from the given data. The operator object is default initialized.
Returns the sine of the operand.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::AbsOp > abs(const Integer &i)
Computes and returns the absolute value of i.
Returns the square root of the operand.
Returns the arcus cosine of the operand. Uses the context stored in the operator. ...
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::LCMOp > LCM(const Integer &a, const Integer &b)
Computes and returns the non-negative Least Common Multiple of a and b.
Returns the arcus sine of the operand.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::CeilDivOp > ceilDiv(const Integer &a, const Integer &b)
Computes and returns .
unsigned long precision() const
Returns the precision of the expression. Only compiles if the expression supports this...
Returns the logarithm to base 2 of the operand.
expressions::Expression< RealContext, std::pair< expressions::Wrapper< RealContext >, expressions::Wrapper< RealContext > >, expressions::ATan2Op > atan2(const Real &y, const Real &x)
Returns the arctangent of , using the signs of x and y to determine the quadrant. ...
const Context & context() const
Allows to access the expression's context. This function only compiles if a context is stored in the ...
Expression(const Data &data, const Op< Context_, Data > &op)
Creates an expression from the given data and operator object.
Returns the bitwise AND of the operands.
Returns the exponential of the operand. Uses the context stored in the operator.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::Log2Op > log2(const Real &i)
Returns the base-2 logarithm evaluated at the given floating point number.
unsigned long precision() const
Returns the precision of the variable.
Returns the operand multiplied by 2 to the power of a constant.
void mul(Integer &r, const Integer &a, const Integer &b)
Multiplies a with b and stores the result in r.
Provides conversion implementation from type SourceType to DestContext::Type.
Definition: arithmetic.hpp:713
void div(Integer &r, const Integer &a, const Integer &b)
Divides a by b and stores the result in r.
Returns the natural logarithm of the operand. Uses the context stored in the operator.
Returns the quotient of the operands.
void convert(typename DestContext::Type &dst, const SourceType &src, const DestContext &context)
Converts the value in src to the type described by context and stores the result in dst...
Definition: arithmetic.hpp:734
const Data & data() const
Allows to access the expression's data.
Returns the arcus tangent of the quotient of the operands.
Returns the absolute value of the operand. Uses the context stored in the operator.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::LogOp > log(const Real &i)
Returns the natural logarithm evaluated at the given floating point number.
void mod(Integer &r, const Integer &a, const Integer &b)
Takes the remainder of the division of a by b and stores it in r.
Wrapper(const typename Context_::Type &value)
Initializes the wrapper object with the given variable.
Converts the argument to the destination type by rounding. Uses the context stored in the operator an...
const Context_::Type & evaluate() const
"Evaluates" (returns) the stored value.
Conversion from compile-time known bools to types.
Definition: helper.hpp:220
Returns the cosine of the operand. Uses the context stored in the operator.
Returns the square of the operand. Uses the context stored in the operator.
Implementation backend for conversions from context types to native types.
Definition: arithmetic.hpp:994
Converts the argument to the destination type by rounding down (floor). Uses the context stored in th...
Returns the arcus tangent of the quotient of the operands. Uses the context stored in the operator...
void convert_round(typename DestContext::Type &dst, const SourceType &src, const DestContext &context)
Converts the rounded value in src to the type described by context and stores the result in dst...
Definition: arithmetic.hpp:863
Returns the logarithm of the absolute value of the Gamma function evaluated of the operand together w...
void bor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise or of a and b and stores the result in r.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::PowerOp > power(const Integer &a, const Integer &b)
Computes and returns a raised to the power of b.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SqrtCeilOp > sqrtCeil(const Integer &i)
Computes and returns the ceil of the square root of i.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::SinOp > sin(const Real &i)
Returns the sine of the given floating point number.
Returns the floor of the square root of the operand.
void bxor(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise exclusive or of a and b and stores the result in r.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ASinOp > asin(const Real &i)
Returns the arcsine of the given floating point number.
const Op< Context_, Data > & op() const
Allows to access the operator object.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::Log10Op > log10(const Real &i)
Returns the base-10 logarithm evaluated at the given floating point number.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::ACosOp > acos(const Real &i)
Returns the arccosine of the given floating point number.
Returns the product of the operands.
Converts the argument to the destination type by rounding up (ceil). Uses the context stored in the o...
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::RoundDivOp > roundDiv(const Integer &a, const Integer &b)
Computes and returns .
int sign(const Integer &) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
Returns the sign of the given integer.
Returns the natural logarithm of the operand.
Returns the logarithm to base 10 of the operand. Uses the context stored in the operator.
Expression< Context, Wrapper< Context >, NoneOp > make_expression(const typename Context::Type &a)
Creates an expression from a type.
void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
Returns the Gamma function evaluated of the operand. Uses the context stored in the operator...
void band(Integer &r, const Integer &a, const Integer &b)
Computes the bitwise and of a and b and stores the result in r.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::CosOp > cos(const Real &i)
Returns the cosine of the given floating point number.
Returns the cosine of the operand.
Returns the logarithm of the absolute value of the Gamma function evaluated of the operand...
Returns the logarithm to base 2 of the operand. Uses the context stored in the operator.
Returns the remainder of the operands.
void neg(Integer &r, const Integer &a)
Negates a and stores the result in r.
Returns the power of the first operand to the second operand.
Returns the exponential of the operand.
Returns the GCD of the two operands.
Returns the Gamma function evaluated of the operand.
Converts the argument to the destination type by rounding. Uses the context stored in the operator...
void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
Returns the power of the operand to a constant stored in the operator object.
Returns the logarithm to base 10 of the operand.
Returns the power of the first operand to the second operand. Uses the context stored in the operator...
Implementation of raising to a power by a constant exponent.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SquareOp > square(const Integer &i)
Computes and returns the square of i.
Returns the logarithm of the absolute value of the Gamma function evaluated of the operand...
Returns the bitwise OR of the operands.
Returns the absolute value of the operand.
void convert_floor(typename DestContext::Type &dst, const SourceType &src, const DestContext &context)
Converts the floor of the value in src to the type described by context and stores the result in dst...
Definition: arithmetic.hpp:819
Returns the LCM of the two operands.
void convert_ceil(typename DestContext::Type &dst, const SourceType &src, const DestContext &context)
Converts the ceil of the value in src to the type described by context and stores the result in dst...
Definition: arithmetic.hpp:955
Returns the bitwise inversion of the operands.
Returns the square of the operand.
Returns the arcus sine of the operand. Uses the context stored in the operator.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::SqrtOp > sqrt(const Real &i)
Returns the square root of the given floating point number.
evaluate_type evaluate() const
Returns the value of the expression.
void assignTo(typename Context::Type &x) const
Evaluates the expression into the given object.
Returns the first operand divided by 2 to the power of the second operand.
expressions::Expression< RealContext, expressions::Wrapper< RealContext >, expressions::LGammaOp > lgamma(const Real &i)
Returns the natural logarithm of the absolute value of the Gamma function evaluated at the given floa...
Returns the arcus tangent of the operand. Uses the context stored in the operator.
Returns the power of the operand to a constant stored in the operator object. Uses the context stored...
Returns the bitwise XOR (exclusive or) of the operands.
Wraps a variable to behave similarly to an Expression<> object.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::GCDOp > GCD(const Integer &a, const Integer &b)
Computes and returns the non-negative Greatest Common Divisor of a and b.
Returns the difference of the operands.
Returns the first operand multiplied by 2 to the power of the second operand.
Main arithmetic header.
void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.