plll  1.0
arithmetic-nint-conv.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__NINT_WRAPPER_CONV
24 #define PLLL_INCLUDE_GUARD__NINT_WRAPPER_CONV
25 
34 #include <plll/rational.hpp>
35 
36 namespace plll
37 {
38  namespace arithmetic
39  {
40  namespace implementation
41  {
42  // Implementation for NIntContext<Type>
43 
44  // To avoid that conversion_impl<NInt<Type>, NIntContext<Type> > is defined twice, we
45  // instanciate these conversions explicitly for distinct types.
46  template<> class conversion_impl<NInt<long>, NIntContext<int> >
47  {
48  public:
49  typedef NInt<int> RetVal;
50  typedef void RetVal_Frac;
51  typedef void RetVal_Floor;
52  typedef void RetVal_Ceil;
53  typedef void RetVal_Round;
54  typedef void RetVal_Round2;
55 
56  static void convert(NInt<int> & d, const NInt<long> & v, const NIntContext<int> & c)
57  {
58  d.d_value = v.d_value;
59  }
60 
61  static RetVal convert(const NInt<long> & v, const NIntContext<int> & c)
62  {
63  return NInt<int>(false, v.d_value);
64  }
65  };
66 
67  template<> class conversion_impl<NInt<long long>, NIntContext<int> >
68  {
69  public:
70  typedef NInt<int> RetVal;
71  typedef void RetVal_Frac;
72  typedef void RetVal_Floor;
73  typedef void RetVal_Ceil;
74  typedef void RetVal_Round;
75  typedef void RetVal_Round2;
76 
77  static void convert(NInt<int> & d, const NInt<long long> & v, const NIntContext<int> & c)
78  {
79  d.d_value = v.d_value;
80  }
81 
82  static RetVal convert(const NInt<long long> & v, const NIntContext<int> & c)
83  {
84  return NInt<int>(false, v.d_value);
85  }
86  };
87 
88  template<> class conversion_impl<NInt<int>, NIntContext<long> >
89  {
90  public:
91  typedef NInt<long> RetVal;
92  typedef void RetVal_Frac;
93  typedef void RetVal_Floor;
94  typedef void RetVal_Ceil;
95  typedef void RetVal_Round;
96  typedef void RetVal_Round2;
97 
98  static void convert(NInt<long> & d, const NInt<int> & v, const NIntContext<long> & c)
99  {
100  d.d_value = v.d_value;
101  }
102 
103  static RetVal convert(const NInt<int> & v, const NIntContext<long> & c)
104  {
105  return NInt<long>(false, v.d_value);
106  }
107  };
108 
109  template<> class conversion_impl<NInt<long long>, NIntContext<long> >
110  {
111  public:
112  typedef NInt<long> RetVal;
113  typedef void RetVal_Frac;
114  typedef void RetVal_Floor;
115  typedef void RetVal_Ceil;
116  typedef void RetVal_Round;
117  typedef void RetVal_Round2;
118 
119  static void convert(NInt<long> & d, const NInt<long long> & v, const NIntContext<long> & c)
120  {
121  d.d_value = v.d_value;
122  }
123 
124  static RetVal convert(const NInt<long long> & v, const NIntContext<long> & c)
125  {
126  return NInt<long>(false, v.d_value);
127  }
128  };
129 
130  template<> class conversion_impl<NInt<int>, NIntContext<long long> >
131  {
132  public:
133  typedef NInt<long long> RetVal;
134  typedef void RetVal_Frac;
135  typedef void RetVal_Floor;
136  typedef void RetVal_Ceil;
137  typedef void RetVal_Round;
138  typedef void RetVal_Round2;
139 
140  static void convert(NInt<long long> & d, const NInt<int> & v, const NIntContext<long long> & c)
141  {
142  d.d_value = v.d_value;
143  }
144 
145  static RetVal convert(const NInt<int> & v, const NIntContext<long long> & c)
146  {
147  return NInt<long long>(false, v.d_value);
148  }
149  };
150 
151  template<> class conversion_impl<NInt<long>, NIntContext<long long> >
152  {
153  public:
154  typedef NInt<long long> RetVal;
155  typedef void RetVal_Frac;
156  typedef void RetVal_Floor;
157  typedef void RetVal_Ceil;
158  typedef void RetVal_Round;
159  typedef void RetVal_Round2;
160 
161  static void convert(NInt<long long> & d, const NInt<long> & v, const NIntContext<long long> & c)
162  {
163  d.d_value = v.d_value;
164  }
165 
166  static RetVal convert(const NInt<long> & v, const NIntContext<long long> & c)
167  {
168  return NInt<long long>(false, v.d_value);
169  }
170  };
171 
172  template<typename Type> class conversion_impl<signed int, NIntContext<Type> >
173  {
174  public:
175  typedef NInt<Type> RetVal;
176  typedef void RetVal_Frac;
177  typedef void RetVal_Floor;
178  typedef void RetVal_Ceil;
179  typedef void RetVal_Round;
180  typedef void RetVal_Round2;
181 
182  static void convert(NInt<Type> & d, signed int v, const NIntContext<Type> & c)
183  {
184  d.d_value = v;
185  }
186 
187  static RetVal convert(signed int v, const NIntContext<Type> & c)
188  {
189  return NInt<Type>(false, v);
190  }
191  };
192 
193  template<typename Type> class conversion_impl<unsigned int, NIntContext<Type> >
194  {
195  public:
196  typedef NInt<Type> RetVal;
197  typedef void RetVal_Frac;
198  typedef void RetVal_Floor;
199  typedef void RetVal_Ceil;
200  typedef void RetVal_Round;
201  typedef void RetVal_Round2;
202 
203  static void convert(NInt<Type> & d, unsigned int v, const NIntContext<Type> & c)
204  {
205  d.d_value = v;
206  }
207 
208  static RetVal convert(unsigned int v, const NIntContext<Type> & c)
209  {
210  return NInt<Type>(false, v);
211  }
212  };
213 
214  template<typename Type> class conversion_impl<signed long, NIntContext<Type> >
215  {
216  public:
217  typedef NInt<Type> RetVal;
218  typedef void RetVal_Frac;
219  typedef void RetVal_Floor;
220  typedef void RetVal_Ceil;
221  typedef void RetVal_Round;
222  typedef void RetVal_Round2;
223 
224  static void convert(NInt<Type> & d, signed long v, const NIntContext<Type> & c)
225  {
226  d.d_value = v;
227  }
228 
229  static RetVal convert(signed long v, const NIntContext<Type> & c)
230  {
231  return NInt<Type>(false, v);
232  }
233  };
234 
235  template<typename Type> class conversion_impl<unsigned long, NIntContext<Type> >
236  {
237  public:
238  typedef NInt<Type> RetVal;
239  typedef void RetVal_Frac;
240  typedef void RetVal_Floor;
241  typedef void RetVal_Ceil;
242  typedef void RetVal_Round;
243  typedef void RetVal_Round2;
244 
245  static void convert(NInt<Type> & d, unsigned long v, const NIntContext<Type> & c)
246  {
247  d.d_value = v;
248  }
249 
250  static RetVal convert(unsigned long v, const NIntContext<Type> & c)
251  {
252  return NInt<Type>(false, v);
253  }
254  };
255 
256  template<typename Type> class conversion_impl<long long, NIntContext<Type> >
257  {
258  public:
259  typedef NInt<Type> RetVal;
260  typedef void RetVal_Frac;
261  typedef void RetVal_Floor;
262  typedef void RetVal_Ceil;
263  typedef void RetVal_Round;
264  typedef void RetVal_Round2;
265 
266  static void convert(NInt<Type> & d, long long v, const NIntContext<Type> & c)
267  {
268  d.d_value = v;
269  }
270 
271  static RetVal convert(long long v, const NIntContext<Type> & c)
272  {
273  return NInt<Type>(false, v);
274  }
275  };
276 
277  template<typename Type> // since there is no std::round for float, double and long double, we have
278  class RoundingNFP; // to implement our own
279 
280  template<>
281  class RoundingNFP<float>
282  {
283  public:
284  static float round(float f) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
285  {
286  return roundf(f);
287  }
288 
289  static float round(float f, bool & up) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
290  {
291  float v = roundf(f);
292  up = v > f;
293  return v;
294  }
295  };
296 
297  template<>
298  class RoundingNFP<double>
299  {
300  public:
301  static double round(double d) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
302  {
303  return ::round(d);
304  }
305 
306  static double round(double d, bool & up) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
307  {
308  double v = ::round(d);
309  up = v > d;
310  return v;
311  }
312  };
313 
314  template<>
315  class RoundingNFP<long double>
316  {
317  public:
318  static long double round(long double ld) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
319  {
320  return roundl(ld);
321  }
322 
323  static long double round(long double ld, bool & up) PLLL_INTERNAL_NOTHROW_POSTFIX_INLINE
324  {
325  long double v = roundl(ld);
326  up = v > ld;
327  return v;
328  }
329  };
330 
331  template<typename Type> class conversion_impl<float, NIntContext<Type> >
332  {
333  public:
334  typedef NInt<Type> RetVal;
335  typedef void RetVal_Frac;
336  typedef NInt<Type> RetVal_Floor;
337  typedef NInt<Type> RetVal_Round;
338  typedef NInt<Type> RetVal_Round2;
339  typedef NInt<Type> RetVal_Ceil;
340 
341  static void convert(NInt<Type> & d, float v, const NIntContext<Type> & c)
342  {
343  d.d_value = v;
344  }
345 
346  static RetVal convert(float v, const NIntContext<Type> & c)
347  {
348  return NInt<Type>(false, v);
349  }
350 
351  static void floor(NInt<Type> & d, float v, const NIntContext<Type> & c)
352  {
353  d.d_value = std::floor(v);
354  }
355 
356  static RetVal_Floor floor(float v, const NIntContext<Type> & c)
357  {
358  return NInt<Type>(false, std::floor(v));
359  }
360 
361  static void round(NInt<Type> & d, float v, const NIntContext<Type> & c)
362  {
363  d.d_value = RoundingNFP<float>::round(v);
364  }
365 
366  static RetVal_Round round(float v, const NIntContext<Type> & c)
367  {
368  return NInt<Type>(false, RoundingNFP<float>::round(v));
369  }
370 
371  static void round(NInt<Type> & d, float v, bool & up, const NIntContext<Type> & c)
372  {
373  d.d_value = RoundingNFP<float>::round(v, up);
374  }
375 
376  static RetVal_Round2 round(float v, bool & up, const NIntContext<Type> & c)
377  {
378  return NInt<Type>(false, RoundingNFP<float>::round(v, up));
379  }
380 
381  static void ceil(NInt<Type> & d, float v, const NIntContext<Type> & c)
382  {
383  d.d_value = std::ceil(v);
384  }
385 
386  static RetVal_Ceil ceil(float v, const NIntContext<Type> & c)
387  {
388  return NInt<Type>(false, std::ceil(v));
389  }
390  };
391 
392  template<typename Type> class conversion_impl<double, NIntContext<Type> >
393  {
394  public:
395  typedef NInt<Type> RetVal;
396  typedef void RetVal_Frac;
397  typedef NInt<Type> RetVal_Floor;
398  typedef NInt<Type> RetVal_Round;
399  typedef NInt<Type> RetVal_Round2;
400  typedef NInt<Type> RetVal_Ceil;
401 
402  static void convert(NInt<Type> & d, double v, const NIntContext<Type> & c)
403  {
404  d.d_value = v;
405  }
406 
407  static RetVal convert(double v, const NIntContext<Type> & c)
408  {
409  return NInt<Type>(false, v);
410  }
411 
412  static void floor(NInt<Type> & d, double v, const NIntContext<Type> & c)
413  {
414  d.d_value = std::floor(v);
415  }
416 
417  static RetVal_Floor floor(double v, const NIntContext<Type> & c)
418  {
419  return NInt<Type>(false, std::floor(v));
420  }
421 
422  static void round(NInt<Type> & d, double v, const NIntContext<Type> & c)
423  {
424  d.d_value = RoundingNFP<double>::round(v);
425  }
426 
427  static RetVal_Round round(double v, const NIntContext<Type> & c)
428  {
429  return NInt<Type>(false, RoundingNFP<double>::round(v));
430  }
431 
432  static void round(NInt<Type> & d, double v, bool & up, const NIntContext<Type> & c)
433  {
434  d.d_value = RoundingNFP<double>::round(v, up);
435  }
436 
437  static RetVal_Round2 round(double v, bool & up, const NIntContext<Type> & c)
438  {
439  return NInt<Type>(false, RoundingNFP<double>::round(v, up));
440  }
441 
442  static void ceil(NInt<Type> & d, double v, const NIntContext<Type> & c)
443  {
444  d.d_value = std::ceil(v);
445  }
446 
447  static RetVal_Ceil ceil(double v, const NIntContext<Type> & c)
448  {
449  return NInt<Type>(false, std::ceil(v));
450  }
451  };
452 
453  template<typename Type> class conversion_impl<long double, NIntContext<Type> >
454  {
455  public:
456  typedef NInt<Type> RetVal;
457  typedef void RetVal_Frac;
458  typedef NInt<Type> RetVal_Floor;
459  typedef NInt<Type> RetVal_Round;
460  typedef NInt<Type> RetVal_Round2;
461  typedef NInt<Type> RetVal_Ceil;
462 
463  static void convert(NInt<Type> & d, long double v, const NIntContext<Type> & c)
464  {
465  d.d_value = v;
466  }
467 
468  static RetVal convert(long double v, const NIntContext<Type> & c)
469  {
470  return NInt<Type>(false, v);
471  }
472 
473  static void floor(NInt<Type> & d, long double v, const NIntContext<Type> & c)
474  {
475  d.d_value = std::floor(v);
476  }
477 
478  static RetVal_Floor floor(long double v, const NIntContext<Type> & c)
479  {
480  return NInt<Type>(false, std::floor(v));
481  }
482 
483  static void round(NInt<Type> & d, long double v, const NIntContext<Type> & c)
484  {
485  d.d_value = RoundingNFP<long double>::round(v);
486  }
487 
488  static RetVal_Round round(long double v, const NIntContext<Type> & c)
489  {
491  }
492 
493  static void round(NInt<Type> & d, long double v, bool & up, const NIntContext<Type> & c)
494  {
495  d.d_value = RoundingNFP<long double>::round(v, up);
496  }
497 
498  static RetVal_Round2 round(long double v, bool & up, const NIntContext<Type> & c)
499  {
500  return NInt<Type>(false, RoundingNFP<long double>::round(v, up));
501  }
502 
503  static void ceil(NInt<Type> & d, long double v, const NIntContext<Type> & c)
504  {
505  d.d_value = std::ceil(v);
506  }
507 
508  static RetVal_Ceil ceil(long double v, const NIntContext<Type> & c)
509  {
510  return NInt<Type>(false, std::ceil(v));
511  }
512  };
513 
514  template<typename Type> class conversion_impl<Integer, NIntContext<Type> >
515  {
516  public:
517  typedef NInt<Type> RetVal;
518  typedef void RetVal_Frac;
519  typedef void RetVal_Floor;
520  typedef void RetVal_Ceil;
521  typedef void RetVal_Round;
522  typedef void RetVal_Round2;
523 
524  static void convert(NInt<Type> & d, const Integer & v, const NIntContext<Type> & c)
525  {
526  d.d_value = arithmetic::convert<Type>(v);
527  }
528 
529  static RetVal convert(const Integer & v, const NIntContext<Type> & c)
530  {
531  return NInt<Type>(false, arithmetic::convert<Type>(v));
532  }
533  };
534 
535  template<typename Type> class conversion_impl<NInt<Type>, IntegerContext>
536  {
537  public:
538  typedef typename conversion_impl<Type, IntegerContext>::RetVal RetVal;
539  typedef void RetVal_Frac;
540  typedef void RetVal_Floor;
541  typedef void RetVal_Ceil;
542  typedef void RetVal_Round;
543  typedef void RetVal_Round2;
544 
545  static void convert(Integer & d, const NInt<Type> & v, const IntegerContext & c)
546  {
548  }
549 
550  static RetVal convert(const NInt<Type> & v, const IntegerContext & c)
551  {
553  }
554  };
555 
556  template<typename Type> class conversion_impl<Real, NIntContext<Type> >
557  {
558  public:
559  typedef NInt<Type> RetVal;
560  typedef void RetVal_Frac;
561  typedef NInt<Type> RetVal_Floor;
562  typedef NInt<Type> RetVal_Round;
563  typedef NInt<Type> RetVal_Round2;
564  typedef NInt<Type> RetVal_Ceil;
565 
566  static void convert(NInt<Type> & d, const Real & v, const NIntContext<Type> & c)
567  {
568  d.d_value = arithmetic::convert<Type>(v);
569  }
570 
571  static RetVal convert(const Real & v, const NIntContext<Type> & c)
572  {
573  return NInt<Type>(false, arithmetic::convert<Type>(v));
574  }
575 
576  static void floor(NInt<Type> & d, const Real & v, const NIntContext<Type> & c)
577  {
578  d.d_value = convert_floor<Type>(v);
579  }
580 
581  static RetVal_Floor floor(const Real & v, const NIntContext<Type> & c)
582  {
583  return NInt<Type>(false, convert_floor<Type>(v));
584  }
585 
586  static void round(NInt<Type> & d, const Real & v, const NIntContext<Type> & c)
587  {
588  d.d_value = convert_round<Type>(v);
589  }
590 
591  static RetVal_Round round(const Real & v, const NIntContext<Type> & c)
592  {
593  return NInt<Type>(false, convert_round<Type>(v));
594  }
595 
596  static void round(NInt<Type> & d, const Real & v, bool & up, const NIntContext<Type> & c)
597  {
598  d.d_value = convert_round<Type>(v, up);
599  }
600 
601  static RetVal_Round2 round(const Real & v, bool & up, const NIntContext<Type> & c)
602  {
603  return NInt<Type>(false, convert_round<Type>(v, up));
604  }
605 
606  static void ceil(NInt<Type> & d, const Real & v, const NIntContext<Type> & c)
607  {
608  d.d_value = convert_ceil<Type>(v);
609  }
610 
611  static RetVal_Ceil ceil(const Real & v, const NIntContext<Type> & c)
612  {
613  return NInt<Type>(false, convert_ceil<Type>(v));
614  }
615  };
616 
617  template<typename Type> class conversion_impl<NInt<Type>, RealContext>
618  {
619  public:
620  typedef typename conversion_impl<Type, RealContext>::RetVal RetVal;
621  typedef typename conversion_impl<Type, RealContext>::RetVal_Frac RetVal_Frac;
622  typedef void RetVal_Floor;
623  typedef void RetVal_Ceil;
624  typedef void RetVal_Round;
625  typedef void RetVal_Round2;
626 
627  static void convert(Real & d, const NInt<Type> & v, const RealContext & c)
628  {
630  }
631 
632  static RetVal convert(const NInt<Type> & v, const RealContext & c)
633  {
634  return conversion_impl<Type, RealContext>::convert(v.d_value, c);
635  }
636 
637  static void convert_frac(Real & d, const NInt<Type> & v1, const NInt<Type> & v2, const RealContext & c)
638  {
639  conversion_impl<Type, RealContext>::convert_frac(d, v1.d_value, v2.d_value, c);
640  }
641 
642  static RetVal_Frac convert_frac(const NInt<Type> & v1, const NInt<Type> & v2, const RealContext & c)
643  {
644  return conversion_impl<Type, RealContext>::convert_frac(v1.d_value, v2.d_value, c);
645  }
646  };
647 
648  template<typename Type> class conversion_impl<Rational, NIntContext<Type> >
649  {
650  public:
651  typedef NInt<Type> RetVal;
652  typedef void RetVal_Frac;
653  typedef NInt<Type> RetVal_Floor;
654  typedef NInt<Type> RetVal_Round;
655  typedef NInt<Type> RetVal_Round2;
656  typedef NInt<Type> RetVal_Ceil;
657 
658  static void convert(NInt<Type> & d, const Rational & v, const NIntContext<Type> & c)
659  {
660  d.d_value = arithmetic::convert<Type>(v);
661  }
662 
663  static RetVal convert(const Rational & v, const NIntContext<Type> & c)
664  {
665  return NInt<Type>(false, arithmetic::convert<Type>(v));
666  }
667 
668  static void floor(NInt<Type> & d, const Rational & v, const NIntContext<Type> & c)
669  {
670  d.d_value = convert_floor<Type>(v);
671  }
672 
673  static RetVal_Floor floor(const Rational & v, const NIntContext<Type> & c)
674  {
675  return NInt<Type>(false, convert_floor<Type>(v));
676  }
677 
678  static void round(NInt<Type> & d, const Rational & v, const NIntContext<Type> & c)
679  {
680  d.d_value = convert_round<Type>(v);
681  }
682 
683  static RetVal_Round round(const Rational & v, const NIntContext<Type> & c)
684  {
685  return NInt<Type>(false, convert_round<Type>(v));
686  }
687 
688  static void round(NInt<Type> & d, const Rational & v, bool & up, const NIntContext<Type> & c)
689  {
690  d.d_value = convert_round<Type>(v, up);
691  }
692 
693  static RetVal_Round2 round(const Rational & v, bool & up, const NIntContext<Type> & c)
694  {
695  return NInt<Type>(false, convert_round<Type>(v, up));
696  }
697 
698  static void ceil(NInt<Type> & d, const Rational & v, const NIntContext<Type> & c)
699  {
700  d.d_value = convert_ceil<Type>(v);
701  }
702 
703  static RetVal_Ceil ceil(const Rational & v, const NIntContext<Type> & c)
704  {
705  return NInt<Type>(false, convert_ceil<Type>(v));
706  }
707  };
708 
709  template<typename Type> class conversion_impl<NInt<Type>, RationalContext>
710  {
711  public:
712  typedef typename conversion_impl<Type, RationalContext>::RetVal RetVal;
713  typedef typename conversion_impl<Type, RationalContext>::RetVal_Frac RetVal_Frac;
714  typedef void RetVal_Floor;
715  typedef void RetVal_Ceil;
716  typedef void RetVal_Round;
717  typedef void RetVal_Round2;
718 
719  static void convert(Rational & d, const NInt<Type> & v, const RationalContext & c)
720  {
722  }
723 
724  static RetVal convert(const NInt<Type> & v, const RationalContext & c)
725  {
727  }
728 
729  static void convert_frac(Rational & d, const NInt<Type> & v1, const NInt<Type> & v2, const RationalContext & c)
730  {
731  conversion_impl<Type, RationalContext>::convert_frac(d, v1.d_value, v2.d_value, c);
732  }
733 
734  static RetVal_Frac convert_frac(const NInt<Type> & v1, const NInt<Type> & v2, const RationalContext & c)
735  {
736  return conversion_impl<Type, RationalContext>::convert_frac(v1.d_value, v2.d_value, c);
737  }
738  };
739 
740  template<typename Type> class nativeconversion_impl<NInt<Type> >
741  {
742  public:
743  static int toInt(const NInt<Type> & v)
744  {
745  return v.d_value;
746  }
747 
748  static unsigned int toUInt(const NInt<Type> & v)
749  {
750  return v.d_value;
751  }
752 
753  static long toLong(const NInt<Type> & v)
754  {
755  return v.d_value;
756  }
757 
758  static unsigned long toULong(const NInt<Type> & v)
759  {
760  return v.d_value;
761  }
762 
763  static long long toLongLong(const NInt<Type> & v)
764  {
765  return v.d_value;
766  }
767 
768  static float toFloat(const NInt<Type> & v)
769  {
770  return v.d_value;
771  }
772 
773  static double toDouble(const NInt<Type> & v)
774  {
775  return v.d_value;
776  }
777 
778  static long double toLongDouble(const NInt<Type> & v)
779  {
780  return v.d_value;
781  }
782  };
783 
784  template<typename Type, typename Op>
785  struct binary_operation_impl<NInt<Type>, NInt<Type>, Op>
786  {
787  enum { supported = true, intermediate_expression = false };
789  typedef NInt<Type> ResultType;
790  };
791 
792  template<typename Type>
793  struct unary_operation_impl<NInt<Type>, arithmetic::op::negation>
794  {
795  enum { supported = true, intermediate_expression = false };
797  typedef NInt<Type> ResultType;
798  };
799  }
800  }
801 }
802 
803 #endif
Provides information on the result of an unary arithmetic operation.
Definition: arithmetic.hpp:138
Header for rational number arithmetic.
Provides conversion implementation from type SourceType to DestContext::Type.
Definition: arithmetic.hpp:713
Provides information on the result of a binary arithmetic operation.
Definition: arithmetic.hpp:79
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
Implementation backend for conversions from context types to native types.
Definition: arithmetic.hpp:994
Represents a rational number as a quotient of two arbitrary precision integers.
Definition: rational.hpp:431
Represents a native integer.
Represents an arbitrary precision floating point value.
Represents an arithmetic context for arbitrary precision floating point values.
Represents an arbitrary precision integer.
Represents an arithmetic context for native integers.
Represents an arithmetic context for rational numbers.
Definition: rational.hpp:355
Represents an arithmetic context for arbitrary precision integer.