carl  24.04
Computer ARithmetic Library
FLOAT_T.h
Go to the documentation of this file.
1 /**
2  * General class for floating point numbers with different formats. Extend to
3  * other types if necessary.
4  *
5  * @file FLOAT_T.h
6  * @author Stefan Schupp <stefan.schupp@cs.rwth-aachen.de>
7  * @since 2013-10-14
8  * @version 2014-08-28
9  */
10 
11 #pragma once
12 
13 #ifndef INCLUDED_FROM_NUMBERS_H
14 static_assert(false, "This file may only be included indirectly by numbers.h");
15 #endif
16 
17 
18 #include <carl-common/util/hash.h>
20 #include "roundingConversion.h"
21 
22 #include <cfloat>
23 #include <cmath>
24 #include <cstddef>
25 #include <iostream>
26 #include <string>
27 
28 namespace carl
29 {
30  using precision_t = std::size_t;
31 
32  template<typename Number>
33  class Interval;
34 
35  template<typename FloatType>
36  class FLOAT_T;
37 
38  /**
39  * Struct which holds the conversion operator for any two instanciations of
40  * FLOAT_T with different underlying floating point implementations. Note
41  * that this conversion introduces loss of precision, as it uses the to_double()
42  * method and the corresponding double constructor from the target type.
43  */
44  template<typename T1, typename T2>
45  struct FloatConv
46  {
47  /**
48  * Conversion operator for conversion of two instanciations of FLOAT_T
49  * with different underlying floating point implementations.
50  * @param _op2 The source instanciation (T2)
51  * @return returns an instanciation with different floating point implementation (T1)
52  */
53  FLOAT_T<T1> operator() (const FLOAT_T<T2>& _op2) const
54  {
55  return FLOAT_T<T1>(_op2.to_double());
56  }
57  };
58 
59 
61 
62  inline Str2Double_Error str2double (double &d, char const *s)
63  {
64  char *end;
65  long double l;
66  errno = 0;
67  l = strtod(s, &end);
68  if ((errno == ERANGE && l == LDBL_MAX) || l > DBL_MAX) {
69  return FLOAT_OVERFLOW;
70  }
71  if ((errno == ERANGE && l == LDBL_MIN) || l < DBL_MIN) {
72  return FLOAT_UNDERFLOW;
73  }
74  if (*s == '\0' || *end != '\0') {
75  return FLOAT_INCONVERTIBLE;
76  }
77  d = double(l);
78  return FLOAT_SUCCESS;
79  }
80 
81  // Usable AlmostEqual function taken from http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
82  template<typename Number>
83  inline bool AlmostEqual2sComplement(const Number& A, const Number& B, unsigned /*unused*/ = 128)
84  {
85  return A == B;
86  }
87 
88  template<>
89  inline bool AlmostEqual2sComplement<double>(const double& A, const double& B, unsigned maxUlps)
90  {
91  // Make sure maxUlps is non-negative and small enough that the
92  // default NAN won't compare as equal to anything.
93  assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
94  sint aInt = *reinterpret_cast<const sint*>(&A);
95  // Make aInt lexicographically ordered as a twos-complement int
96  if (aInt < 0)
97  aInt = static_cast<sint>(0x8000000000000000) - aInt;
98  // Make bInt lexicographically ordered as a twos-complement int
99  sint bInt = *reinterpret_cast<const sint*>(&B);
100  if (bInt < 0)
101  bInt = static_cast<sint>(0x8000000000000000) - bInt;
102  auto intDiff = static_cast<uint>(std::abs(aInt - bInt));
103  return intDiff <= maxUlps;
104  }
105 
106  /**
107  * Templated wrapper class which allows universal usage of different
108  * IEEE 754 implementations.
109  * For each implementation intended to use it is necessary to implement the
110  * according specialization of this class.
111  */
112  template<typename FloatType>
113  class FLOAT_T
114  {
115  static_assert(carl::is_subset_of_integers_type<FloatType>::value == false, "FLOAT_T may not be used with integers.");
116  private:
117  FloatType mValue;
118 
119  public:
120 
121  /**
122  * Default empty constructor, which initializes to zero.
123  */
125  mValue()
126  {}
127 
128  /**
129  * Constructor, which takes a double as input and optional rounding, which
130  * can be used, if the underlying fp implementation allows this.
131  * @param _double Value to be initialized.
132  * @param N Possible rounding direction.
133  */
134  explicit FLOAT_T(double _double, CARL_RND /*unused*/ = CARL_RND::N):
135  mValue(carl::convert<double, FloatType>(_double))
136  {
137  }
138 
139  /**
140  * Constructor, which takes an integer as input and optional rounding, which
141  * can be used, if the underlying fp implementation allows this.
142  * @param _int Value to be initialized.
143  * @param N Possible rounding direction.
144  */
145  explicit FLOAT_T(sint _int, CARL_RND /*unused*/ = CARL_RND::N):
146  mValue(FloatType(_int))
147  {
148  }
149 
150  explicit FLOAT_T(int _int, CARL_RND /*unused*/ = CARL_RND::N):
151  mValue(FloatType(_int))
152  {
153  }
154 
155  /**
156  * Constructor, which takes an unsigned integer as input and optional rounding, which
157  * can be used, if the underlying fp implementation allows this.
158  * @param _int Value to be initialized.
159  * @param N Possible rounding direction.
160  */
161  explicit FLOAT_T(unsigned _int, CARL_RND /*unused*/ = CARL_RND::N):
162  mValue(FloatType(_int))
163  {
164  }
165 
166  /**
167  * Copyconstructor which takes a FLOAT_T<FloatType> and optional rounding
168  * as input, which can be used, if the underlying fp implementation
169  * allows this.
170  * @param _float Value to be initialized.
171  * @param N Possible rounding direction.
172  */
173  FLOAT_T(const FLOAT_T& _float, CARL_RND /*unused*/ = CARL_RND::N) : mValue(_float.mValue)
174  {}
175 
176  FLOAT_T(FLOAT_T&& _float, CARL_RND /*unused*/ = CARL_RND::N) noexcept : mValue(std::move(_float.value())) // NOLINT
177  {}
178 
179  /**
180  * Constructor, which takes an arbitrary fp type as input and optional rounding, which
181  * can be used, if the underlying fp implementation allows this.
182  * @param val Value to be initialized.
183  * @param N Possible rounding direction.
184  */
185  template<typename F = FloatType, DisableIf< std::is_same<F, double> > = dummy>
186  explicit FLOAT_T(FloatType val, CARL_RND /*unused*/ = CARL_RND::N):
187  mValue(std::move(val))
188  {
189  }
190 
191  template<typename F = FloatType, EnableIf< carl::is_rational_type<F> > = dummy>
192  explicit FLOAT_T(const std::string& _string, CARL_RND /*unused*/ = CARL_RND::N):
193  mValue(carl::parse<FloatType>(_string))
194  {
195  }
196 
197  template<typename F = FloatType, EnableIf< std::is_same<F, double> > = dummy>
198  explicit FLOAT_T(const std::string& _string, CARL_RND /*unused*/ = CARL_RND::N):
199  mValue(std::stod(_string))
200  {
201  }
202 
203  /**
204  * Destructor. Note that for some specializations memory management has to
205  * be included here.
206  */
207  ~FLOAT_T() = default;
208 
209  /**
210  * Getter for the raw value contained.
211  * @return Raw value.
212  */
213  const FloatType& value() const {
214  return mValue;
215  }
216 
217  /**
218  * If precision is used, this getter returns the acutal precision (default:
219  * 53 bit).
220  * @return Precision.
221  */
223  {
224  return 0;
225  }
226 
227  /**
228  * Allows to set the desired precision. Note: If the value is already
229  * initialized this can change the internal value.
230  * @param Precision in bits.
231  * @return Reference to this.
232  */
233  FLOAT_T& setPrecision(const precision_t& /*unused*/)
234  {
235  return *this;
236  }
237 
238  /**
239  * Assignment operator.
240  * @param _rhs Righthand side of the assignment.
241  * @return Reference to this.
242  */
243  FLOAT_T& operator =(const FLOAT_T& _rhs) = default;
244 
245  FLOAT_T& operator =(const FloatType& _rhs)
246  {
247  mValue = _rhs;
248  return *this;
249  }
250 
251  /**
252  * Comparison operator for equality.
253  * @param _rhs Righthand side of the comparison.
254  * @return True if _rhs equals this.
255  */
256  bool operator ==(const FLOAT_T& _rhs) const
257  {
258  //std::cout << "COMPARISON: " << *this << " == " << _rhs << " : " << (mValue == _rhs.mValue) << std::endl;
259  return mValue == _rhs.mValue;
260  // return AlmostEqual2sComplement(double(mValue), double(_rhs.mValue), 4);
261  }
262 
263  /**
264  * Comparison operator for inequality.
265  * @param _rhs Righthand side of the comparison.
266  * @return True if _rhs is unequal to this.
267  */
268  bool operator !=(const FLOAT_T & _rhs) const
269  {
270  return mValue != _rhs.mValue;
271  }
272 
273  /**
274  * Comparison operator for larger than.
275  * @param _rhs Righthand side of the comparison.
276  * @return True if _rhs is larger than this.
277  */
278  bool operator>(const FLOAT_T & _rhs) const
279  {
280  return mValue > _rhs.mValue;
281  }
282 
283  bool operator>(int _rhs) const
284  {
285  return mValue > _rhs;
286  }
287 
288  bool operator>(unsigned _rhs) const
289  {
290  return mValue > _rhs;
291  }
292 
293 
294  /**
295  * Comparison operator for less than.
296  * @param _rhs Righthand side of the comparison.
297  * @return True if _rhs is smaller than this.
298  */
299  bool operator<(const FLOAT_T & _rhs) const
300  {
301  return mValue < _rhs.mValue;
302  }
303 
304  bool operator<(int _rhs) const
305  {
306  return mValue < _rhs;
307  }
308 
309  bool operator<(unsigned _rhs) const
310  {
311  return mValue < _rhs;
312  }
313 
314  /**
315  * Comparison operator for less or equal than.
316  * @param _rhs Righthand side of the comparison.
317  * @return True if _rhs is larger or equal than this.
318  */
319  bool operator <=(const FLOAT_T & _rhs) const
320  {
321  return mValue <= _rhs.mValue;
322  }
323 
324  /**
325  * Comparison operator for larger or equal than.
326  * @param _rhs Righthand side of the comparison.
327  * @return True if _rhs is smaller or equal than this.
328  */
329  bool operator >=(const FLOAT_T & _rhs) const
330  {
331  return mValue >= _rhs.mValue;
332  }
333 
334  /**
335  * Function for addition of two numbers, which assigns the result to the
336  * calling number.
337  * @param _op2 Righthand side of the operation
338  * @param N Possible rounding direction.
339  * @return Reference to this.
340  */
341  FLOAT_T& add_assign(const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N)
342  {
343  mValue = mValue + _op2.mValue;
344  return *this;
345  }
346 
347  /**
348  * Function which adds two numbers and puts the result in a third number passed as parameter.
349  * @param _result Result of the operation.
350  * @param _op2 Righthand side of the operation.
351  * @param N Possible rounding direction.
352  * @return Reference to the result.
353  */
354  FLOAT_T& add(FLOAT_T& _result, const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N) const
355  {
356  _result.mValue = mValue + _op2.mValue;
357  return _result;
358  }
359 
360  /**
361  * Function for subtraction of two numbers, which assigns the result to the
362  * calling number.
363  * @param _op2 Righthand side of the operation
364  * @param N Possible rounding direction.
365  * @return Reference to this.
366  */
367  FLOAT_T& sub_assign(const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N)
368  {
369  mValue = mValue - _op2.mValue;
370  return *this;
371  }
372 
373  /**
374  * Function which subtracts the righthand side from this number and puts
375  * the result in a third number passed as parameter.
376  * @param _result Result of the operation.
377  * @param _op2 Righthand side of the operation.
378  * @param N Possible rounding direction.
379  * @return Reference to the result.
380  */
381  FLOAT_T& sub(FLOAT_T& _result, const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N) const
382  {
383  _result.mValue = mValue - _op2.mValue;
384  return _result;
385  }
386 
387  /**
388  * Function for multiplication of two numbers, which assigns the result to the
389  * calling number.
390  * @param _op2 Righthand side of the operation
391  * @param N Possible rounding direction.
392  * @return Reference to this.
393  */
394  FLOAT_T& mul_assign(const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N)
395  {
396  mValue = mValue * _op2.mValue;
397  return *this;
398  }
399 
400  /**
401  * Function which multiplicates two numbers and puts the result in a
402  * third number passed as parameter.
403  * @param _result Result of the operation.
404  * @param _op2 Righthand side of the operation.
405  * @param N Possible rounding direction.
406  * @return Reference to the result.
407  */
408  FLOAT_T& mul(FLOAT_T& _result, const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N) const
409  {
410  _result.mValue = mValue * _op2.mValue;
411  return _result;
412  }
413 
414  /**
415  * Function for division of two numbers, which assigns the result to the
416  * calling number.
417  * @param _op2 Righthand side of the operation
418  * @param N Possible rounding direction.
419  * @return Reference to this.
420  */
421  FLOAT_T& div_assign(const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N)
422  {
423  assert(!is_zero(_op2));
424  mValue = mValue / _op2.mValue;
425  return *this;
426  }
427 
428  /**
429  * Function which divides this number by the righthand side and puts the
430  * result in a third number passed as parameter.
431  * @param _result Result of the operation.
432  * @param _op2 Righthand side of the operation.
433  * @param N Possible rounding direction.
434  * @return Reference to the result.
435  */
436  FLOAT_T& div(FLOAT_T& _result, const FLOAT_T& _op2, CARL_RND /*unused*/ = CARL_RND::N) const
437  {
438  assert(_op2 != 0);
439  _result.mValue = mValue / _op2.mValue;
440  return _result;
441  }
442 
443  /**
444  * Function for the square root of the number, which assigns the result to the
445  * calling number.
446  * @param N Possible rounding direction.
447  * @return Reference to this.
448  */
450  {
451  assert(mValue >= 0);
453  return *this;
454  }
455 
456  /**
457  * Returns the square root of this number and puts it into a passed result
458  * parameter.
459  * @param _result Result.
460  * @param N Possible rounding direction.
461  * @return Reference to the result.
462  */
463  FLOAT_T& sqrt(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
464  {
465  assert(mValue >= 0);
466  _result.mValue = carl::sqrt(mValue);
467  return _result;
468  }
469 
470  /**
471  * Function for the cubic root of the number, which assigns the result to the
472  * calling number.
473  * @param N Possible rounding direction.
474  * @return Reference to this.
475  */
477  {
478  assert(*this >= 0);
479  mValue = std::cbrt(mValue);
480  return *this;
481  }
482 
483  /**
484  * Returns the cubic root of this number and puts it into a passed result
485  * parameter.
486  * @param _result Result.
487  * @param N Possible rounding direction.
488  * @return Reference to the result.
489  */
490  FLOAT_T& cbrt(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
491  {
492  assert(*this >= 0);
493  _result.mValue = std::cbrt(mValue);
494  return _result;
495  }
496 
497  /**
498  * Function for the nth root of the number, which assigns the result to the
499  * calling number.
500  * @param Degree of the root.
501  * @param N Possible rounding direction.
502  * @return Reference to this.
503  */
504  FLOAT_T& root_assign(std::size_t /*unused*/, CARL_RND /*unused*/ = CARL_RND::N)
505  {
506  assert(*this >= 0);
507  /// @todo implement root_assign for FLOAT_T
508  assert(false && "not implemented");
509  return *this;
510  }
511 
512  /**
513  * Function which calculates the nth root of this number and puts it into a passed result
514  * parameter.
515  * @param Result.
516  * @param Degree of the root.
517  * @param N Possible rounding direction.
518  * @return Reference to the result.
519  */
520  FLOAT_T& root(FLOAT_T& /*unused*/, std::size_t /*unused*/, CARL_RND /*unused*/ = CARL_RND::N) const
521  {
522  assert(*this >= 0);
523  /// @todo implement root for FLOAT_T
524  assert(false && "not implemented");
525  }
526 
527  /**
528  * Function for the nth power of the number, which assigns the result to the
529  * calling number.
530  * @param _exp Exponent.
531  * @param N Possible rounding direction.
532  * @return Reference to this.
533  */
534  FLOAT_T& pow_assign(std::size_t _exp, CARL_RND /*unused*/ = CARL_RND::N)
535  {
536  mValue = std::pow(mValue, _exp);
537  return *this;
538  }
539 
540  /**
541  * Function which calculates the power of this number and puts it into a passed result
542  * parameter.
543  * @param _result Result.
544  * @param _exp Exponent.
545  * @param N Possible rounding direction.
546  * @return Reference to the result.
547  */
548  FLOAT_T& pow(FLOAT_T& _result, std::size_t _exp, CARL_RND /*unused*/ = CARL_RND::N) const
549  {
550  _result.mValue = carl::pow(mValue, _exp);
551  return _result;
552  }
553 
554  /**
555  * Assigns the number the absolute value of this number.
556  * @param N Possible rounding direction.
557  * @return Reference to this.
558  */
560  {
562  return *this;
563  }
564 
565  /**
566  * Function which calculates the absolute value of this number and puts
567  * it into a passed result parameter.
568  * @param _result Result.
569  * @param N Possible rounding direction.
570  * @return Reference to the result.
571  */
572  FLOAT_T& abs(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
573  {
574  _result.mValue = carl::abs(mValue);
575  return _result;
576  }
577 
578  /**
579  * Assigns the number the exponential of this number.
580  * @param N Possible rounding direction.
581  * @return Reference to this.
582  */
584  {
586  return *this;
587  }
588 
589  /**
590  * Function which calculates the exponential of this number and puts
591  * it into a passed result parameter.
592  * @param _result Result.
593  * @param N Possible rounding direction.
594  * @return Reference to the result.
595  */
596  FLOAT_T& exp(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
597  {
598  _result.mValue = std::exp(this->mValue);
599  return _result;
600  }
601 
602  /**
603  * Assigns the number the sine of this number.
604  * @param N Possible rounding direction.
605  * @return Reference to this.
606  */
608  {
610  return *this;
611  }
612 
613  /**
614  * Function which calculates the sine of this number and puts
615  * it into a passed result parameter.
616  * @param _result Result.
617  * @param N Possible rounding direction.
618  * @return Reference to the result.
619  */
620  FLOAT_T& sin(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
621  {
622  _result.mValue = carl::sin(mValue);
623  return _result;
624  }
625 
626  /**
627  * Assigns the number the cosine of this number.
628  * @param N Possible rounding direction.
629  * @return Reference to this.
630  */
632  {
634  return *this;
635  }
636 
637  /**
638  * Function which calculates the cosine of this number and puts
639  * it into a passed result parameter.
640  * @param _result Result.
641  * @param N Possible rounding direction.
642  * @return Reference to the result.
643  */
644  FLOAT_T& cos(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
645  {
646  _result.mValue = carl::cos(mValue);
647  return _result;
648  }
649 
650  /**
651  * Assigns the number the logarithm of this number.
652  * @param N Possible rounding direction.
653  * @return Reference to this.
654  */
656  {
658  return *this;
659  }
660 
661  /**
662  * Function which calculates the logarithm of this number and puts
663  * it into a passed result parameter.
664  * @param _result Result.
665  * @param N Possible rounding direction.
666  * @return Reference to the result.
667  */
668  FLOAT_T& log(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
669  {
670  _result.mValue = carl::log(mValue);
671  return _result;
672  }
673 
674  /**
675  * Assigns the number the tangent of this number.
676  * @param N Possible rounding direction.
677  * @return Reference to this.
678  */
680  {
682  return *this;
683  }
684 
685  /**
686  * Function which calculates the tangent of this number and puts
687  * it into a passed result parameter.
688  * @param _result Result.
689  * @param N Possible rounding direction.
690  * @return Reference to the result.
691  */
692  FLOAT_T& tan(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
693  {
694  _result.mValue = std::tan(mValue);
695  return _result;
696  }
697 
698  /**
699  * Assigns the number the arcus sine of this number.
700  * @param N Possible rounding direction.
701  * @return Reference to this.
702  */
704  {
706  return *this;
707  }
708 
709  /**
710  * Function which calculates the arcus sine of this number and puts
711  * it into a passed result parameter.
712  * @param _result Result.
713  * @param N Possible rounding direction.
714  * @return Reference to the result.
715  */
716  FLOAT_T& asin(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
717  {
718  _result.mValue = std::asin(mValue);
719  return _result;
720  }
721 
722  /**
723  * Assigns the number the arcus cosine of this number.
724  * @param N Possible rounding direction.
725  * @return Reference to this.
726  */
728  {
730  return *this;
731  }
732 
733  /**
734  * Function which calculates the arcus cosine of this number and puts
735  * it into a passed result parameter.
736  * @param _result Result.
737  * @param N Possible rounding direction.
738  * @return Reference to the result.
739  */
740  FLOAT_T& acos(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
741  {
742  _result.mValue = std::acos(mValue);
743  return _result;
744  }
745 
746  /**
747  * Assigns the number the arcus tangent of this number.
748  * @param N Possible rounding direction.
749  * @return Reference to this.
750  */
752  {
754  return *this;
755  }
756 
757  /**
758  * Function which calculates the arcus tangent of this number and puts
759  * it into a passed result parameter.
760  * @param _result Result.
761  * @param N Possible rounding direction.
762  * @return Reference to the result.
763  */
764  FLOAT_T& atan(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
765  {
766  _result.mValue = std::atan(mValue);
767  return _result;
768  }
769 
770  /**
771  * Assigns the number the hyperbolic sine of this number.
772  * @param N Possible rounding direction.
773  * @return Reference to this.
774  */
776  {
778  return *this;
779  }
780 
781  /**
782  * Function which calculates the hyperbolic sine of this number and puts
783  * it into a passed result parameter.
784  * @param _result Result.
785  * @param N Possible rounding direction.
786  * @return Reference to the result.
787  */
788  FLOAT_T& sinh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
789  {
790  _result.mValue = std::sinh(mValue);
791  return _result;
792  }
793 
794  /**
795  * Assigns the number the hyperbolic cosine of this number.
796  * @param N Possible rounding direction.
797  * @return Reference to this.
798  */
800  {
802  return *this;
803  }
804 
805  /**
806  * Function which calculates the hyperbolic cosine of this number and puts
807  * it into a passed result parameter.
808  * @param _result Result.
809  * @param N Possible rounding direction.
810  * @return Reference to the result.
811  */
812  FLOAT_T& cosh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
813  {
814  _result.mValue = std::cosh(mValue);
815  return _result;
816  }
817 
818  /**
819  * Assigns the number the hyperbolic tangent of this number.
820  * @param N Possible rounding direction.
821  * @return Reference to this.
822  */
824  {
826  return *this;
827  }
828 
829  /**
830  * Function which calculates the hyperbolic tangent of this number and puts
831  * it into a passed result parameter.
832  * @param _result Result.
833  * @param N Possible rounding direction.
834  * @return Reference to the result.
835  */
836  FLOAT_T& tanh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
837  {
838  _result.mValue = std::tanh(mValue);
839  return _result;
840  }
841 
842  /**
843  * Assigns the number the hyperbolic arcus sine of this number.
844  * @param N Possible rounding direction.
845  * @return Reference to this.
846  */
848  {
850  return *this;
851  }
852 
853  /**
854  * Function which calculates the hyperbolic arcus sine of this number and puts
855  * it into a passed result parameter.
856  * @param _result Result.
857  * @param N Possible rounding direction.
858  * @return Reference to the result.
859  */
860  FLOAT_T& asinh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
861  {
862  _result.mValue = std::asinh(mValue);
863  return _result;
864  }
865 
866  /**
867  * Assigns the number the hyperbolic arcus cosine of this number.
868  * @param N Possible rounding direction.
869  * @return Reference to this.
870  */
872  {
874  return *this;
875  }
876 
877  /**
878  * Function which calculates the hyperbolic arcus cosine of this number and puts
879  * it into a passed result parameter.
880  * @param _result Result.
881  * @param N Possible rounding direction.
882  * @return Reference to the result.
883  */
884  FLOAT_T& acosh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
885  {
886  _result.mValue = std::acosh(mValue);
887  return _result;
888  }
889 
890  /**
891  * Assigns the number the hyperbolic arcus tangent of this number.
892  * @param N Possible rounding direction.
893  * @return Reference to this.
894  */
896  {
898  return *this;
899  }
900 
901  /**
902  * Function which calculates the hyperbolic arcus tangent of this number and puts
903  * it into a passed result parameter.
904  * @param _result Result.
905  * @param N Possible rounding direction.
906  * @return Reference to the result.
907  */
908  FLOAT_T& atanh(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
909  {
910  _result.mValue = std::atanh(mValue);
911  return _result;
912  }
913 
914  /**
915  * Function which calculates the floor of this number and puts
916  * it into a passed result parameter.
917  * @param _result Result.
918  * @param N Possible rounding direction.
919  * @return Reference to the result.
920  */
921  FLOAT_T& floor(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
922  {
923  _result.mValue = carl::floor(mValue);
924  return _result;
925  }
926 
927  /**
928  * Assigns the number the floor of this number.
929  * @param N Possible rounding direction.
930  * @return Reference to this.
931  */
933  {
935  return *this;
936  }
937 
938  /**
939  * Function which calculates the ceiling of this number and puts
940  * it into a passed result parameter.
941  * @param _result Result.
942  * @param N Possible rounding direction.
943  * @return Reference to the result.
944  */
945  FLOAT_T& ceil(FLOAT_T& _result, CARL_RND /*unused*/ = CARL_RND::N) const
946  {
947  _result.mValue = carl::ceil(mValue);
948  return _result;
949  }
950 
951  /**
952  * Assigns the number the ceiling of this number.
953  * @param N Possible rounding direction.
954  * @return Reference to this.
955  */
957  {
959  return *this;
960  }
961 
962 
963  /**
964  * Function which converts the number to a double value.
965  * @param N Possible rounding direction.
966  * @return Double representation of this
967  */
968  double to_double(CARL_RND /*unused*/ = CARL_RND::N) const
969  {
970  return carl::to_double(mValue);
971  }
972 
973 
974  /**
975  * Explicit typecast operator to integer.
976  * @return Integer representation of this.
977  */
978  explicit operator int() const
979  {
980  if(*this >= 0)
981  return carl::to_int<int>(carl::floor(mValue));
982  else
983  return carl::to_int<int>(carl::ceil(mValue));
984  }
985 
986  /**
987  * Explicit typecast operator to long.
988  * @return Long representation of this.
989  */
990  explicit operator long() const
991  {
992  return carl::to_int<long>(mValue);
993  }
994 
995  /**
996  * Explicit typecast operator to double.
997  * @return Double representation of this.
998  */
999  explicit operator double() const
1000  {
1001  return carl::to_double(mValue);
1002  }
1003 
1004  explicit operator mpq_class() const {
1006  }
1007 
1008 #ifdef USE_CLN_NUMBERS
1009  explicit operator cln::cl_RA() const {
1010  return carl::rationalize<cln::cl_RA>(mValue);
1011  }
1012 #endif
1013 
1014  /**
1015  * Output stream operator for numbers of type FLOAT_T.
1016  * @param ostr Output stream.
1017  * @param p Number.
1018  * @return Reference to the ostream.
1019  */
1020  friend std::ostream& operator<<(std::ostream& ostr, const FLOAT_T& p)
1021  {
1022  ostr << p.mValue;
1023  return ostr;
1024  }
1025 
1026  /**
1027  * Function required for extension of Eigen3 with FLOAT_T as
1028  * a custom type which calculates the complex conjugate.
1029  * @param x The passed number.
1030  * @return Reference to x.
1031  */
1032  inline const FLOAT_T& ei_conj(const FLOAT_T& x)
1033  {
1034  return x;
1035  }
1036 
1037  /**
1038  * Function required for extension of Eigen3 with FLOAT_T as
1039  * a custom type which calculates the real part.
1040  * @param x The passed number.
1041  * @return Reference to x.
1042  */
1043  inline const FLOAT_T& ei_real(const FLOAT_T& x)
1044  {
1045  return x;
1046  }
1047 
1048  /**
1049  * Function required for extension of Eigen3 with FLOAT_T as
1050  * a custom type which calculates the imaginary part.
1051  * @param x The passed number.
1052  * @return Zero.
1053  */
1054  inline FLOAT_T ei_imag(const FLOAT_T& /*unused*/)
1055  {
1056  return FLOAT_T(0);
1057  }
1058 
1059  /**
1060  * Function required for extension of Eigen3 with FLOAT_T as
1061  * a custom type which calculates the absolute value.
1062  * @param x The passed number.
1063  * @return Number which holds the absolute value of x.
1064  */
1065  inline FLOAT_T ei_abs(const FLOAT_T& x)
1066  {
1067  FLOAT_T res;
1068  x.abs(res);
1069  return res;
1070  }
1071 
1072  /**
1073  * Function required for extension of Eigen3 with FLOAT_T as
1074  * a custom type which calculates the absolute value (special Eigen3
1075  * version).
1076  * @param x The passed number.
1077  * @return Number which holds the absolute value of x according to abs2 of Eigen3.
1078  */
1079  inline FLOAT_T ei_abs2(const FLOAT_T& x)
1080  {
1081  FLOAT_T res;
1082  x.mul(res, x);
1083  return res;
1084  }
1085 
1086  /**
1087  * Function required for extension of Eigen3 with FLOAT_T as
1088  * a custom type which calculates the square root.
1089  * @param x The passed number.
1090  * @return Number which holds the square root of x.
1091  */
1092  inline FLOAT_T ei_sqrt(const FLOAT_T& x)
1093  {
1094  FLOAT_T res;
1095  x.sqrt(res);
1096  return res;
1097  }
1098 
1099  /**
1100  * Function required for extension of Eigen3 with FLOAT_T as
1101  * a custom type which calculates the exponential.
1102  * @param x The passed number.
1103  * @return Number which holds the exponential of x.
1104  */
1105  inline FLOAT_T ei_exp(const FLOAT_T& x)
1106  {
1107  FLOAT_T res;
1108  x.exp(res);
1109  return res;
1110  }
1111 
1112  /**
1113  * Function required for extension of Eigen3 with FLOAT_T as
1114  * a custom type which calculates the logarithm.
1115  * @param x The passed number.
1116  * @return Number which holds the logarithm of x.
1117  */
1118  inline FLOAT_T ei_log(const FLOAT_T& x)
1119  {
1120  FLOAT_T res;
1121  x.log(res);
1122  return res;
1123  }
1124 
1125  /**
1126  * Function required for extension of Eigen3 with FLOAT_T as
1127  * a custom type which calculates the sine.
1128  * @param x The passed number.
1129  * @return Number which holds the sine of x.
1130  */
1131  inline FLOAT_T ei_sin(const FLOAT_T& x)
1132  {
1133  FLOAT_T res;
1134  x.sin(res);
1135  return res;
1136  }
1137 
1138  /**
1139  * Function required for extension of Eigen3 with FLOAT_T as
1140  * a custom type which calculates the cosine.
1141  * @param x The passed number.
1142  * @return Number which holds the cosine of x.
1143  */
1144  inline FLOAT_T ei_cos(const FLOAT_T& x)
1145  {
1146  FLOAT_T res;
1147  x.cos(res);
1148  return res;
1149  }
1150 
1151  /**
1152  * Function required for extension of Eigen3 with FLOAT_T as
1153  * a custom type which calculates the power.
1154  * @param x The passed number.
1155  * @param y Degree.
1156  * @return Number which holds the power of x of degree y.
1157  */
1158  inline FLOAT_T ei_pow(const FLOAT_T& x, FLOAT_T y)
1159  {
1160  FLOAT_T res;
1161  x.pow(res, unsigned(y));
1162  return res;
1163  }
1164 
1165  /**
1166  * Operator for addition of two numbers
1167  * @param _lhs Lefthand side.
1168  * @param _rhs Righthand side.
1169  * @return Number which holds the result.
1170  */
1171  friend FLOAT_T operator +(const FLOAT_T& _lhs, const FLOAT_T& _rhs)
1172  {
1173  return FLOAT_T(_lhs.mValue + _rhs.mValue);
1174  }
1175 
1176  /**
1177  * Operator for subtraction of two numbers
1178  * @param _lhs Lefthand side.
1179  * @param _rhs Righthand side.
1180  * @return Number which holds the result.
1181  */
1182  friend FLOAT_T operator -(const FLOAT_T& _lhs, const FLOAT_T& _rhs)
1183  {
1184  return FLOAT_T(_lhs.mValue - _rhs.mValue);
1185  }
1186 
1187  /**
1188  * Operator for unary negation of a number.
1189  * @param _lhs Lefthand side.
1190  * @return Number which holds the result.
1191  */
1192  friend FLOAT_T operator -(const FLOAT_T& _lhs)
1193  {
1194  return FLOAT_T(-1)*_lhs;
1195  }
1196 
1197  /**
1198  * Operator for addition of two numbers.
1199  * @param _lhs Lefthand side.
1200  * @param _rhs Righthand side.
1201  * @return Number which holds the result.
1202  */
1203  friend FLOAT_T operator *(const FLOAT_T& _lhs, const FLOAT_T& _rhs)
1204  {
1205  return FLOAT_T(_lhs.mValue * _rhs.mValue);
1206  }
1207 
1208  /**
1209  * Operator for addition of two numbers.
1210  * @param _lhs Lefthand side.
1211  * @param _rhs Righthand side.
1212  * @return Number which holds the result.
1213  */
1214  friend FLOAT_T operator /(const FLOAT_T& _lhs, const FLOAT_T& _rhs)
1215  {
1216  assert(_rhs != FLOAT_T(0));
1217  return FLOAT_T(_lhs.mValue / _rhs.mValue);
1218  }
1219 
1220  /**
1221  * Operator which increments this number by one.
1222  * @param _num
1223  * @return Reference to _num.
1224  */
1225  friend FLOAT_T& operator ++(FLOAT_T& _num)
1226  {
1227  _num.mValue += FLOAT_T(1);
1228  return _num;
1229  }
1230 
1231  /**
1232  * Operator which decrements this number by one.
1233  * @param _num
1234  * @return Reference to _num.
1235  */
1236  friend FLOAT_T& operator --(FLOAT_T& _num)
1237  {
1238  _num.mValue -= FLOAT_T(1);
1239  return _num;
1240  }
1241 
1242  /**
1243  * Operator which adds the righthand side to this.
1244  * @param _rhs
1245  * @return Reference to this.
1246  */
1248  {
1249  mValue = mValue + _rhs.mValue;
1250  return *this;
1251  }
1252 
1253  /**
1254  * Operator which adds the righthand side of the underlying type to this.
1255  * @param _rhs
1256  * @return Reference to this.
1257  */
1258  FLOAT_T& operator +=(const FloatType& _rhs)
1259  {
1260  mValue = mValue + _rhs;
1261  return *this;
1262  }
1263 
1264  /**
1265  * Operator which subtracts the righthand side from this.
1266  * @param _rhs
1267  * @return Reference to this.
1268  */
1270  {
1271  mValue = mValue - _rhs.mValue;
1272  return *this;
1273  }
1274 
1275  /**
1276  * Operator which subtracts the righthand side of the underlying type from this.
1277  * @param _rhs
1278  * @return Reference to this.
1279  */
1280  FLOAT_T& operator -=(const FloatType& _rhs)
1281  {
1282  mValue = mValue - _rhs;
1283  return *this;
1284  }
1285 
1286  /**
1287  * Operator for unary negation of this number.
1288  * @return Number which holds the negated original number.
1289  */
1291  {
1292  FLOAT_T result = FLOAT_T(*this);
1293  result *= FLOAT_T(-1);
1294  return result;
1295  }
1296 
1297  /**
1298  * Operator which multiplicates this number by the righthand side.
1299  * @param _rhs
1300  * @return Reference to this.
1301  */
1303  {
1304  mValue = mValue * _rhs.mValue;
1305  return *this;
1306  }
1307 
1308  /**
1309  * Operator which multiplicates this number by the righthand side of the
1310  * underlying type.
1311  * @param _rhs
1312  * @return Reference to this.
1313  */
1314  FLOAT_T& operator *=(const FloatType& _rhs)
1315  {
1316  mValue = mValue * _rhs;
1317  return *this;
1318  }
1319 
1320  /**
1321  * Operator which divides this number by the righthand side.
1322  * @param _rhs
1323  * @return Reference to this.
1324  */
1326  {
1327  mValue = mValue / _rhs.mValue;
1328  return *this;
1329  }
1330 
1331  /**
1332  * Operator which divides this number by the righthand side of the underlying
1333  * type.
1334  * @param _rhs
1335  * @return Reference to this.
1336  */
1337  FLOAT_T& operator /=(const FloatType& _rhs)
1338  {
1339  mValue = mValue / _rhs;
1340  return *this;
1341  }
1342 
1343  /**
1344  * Method which converts this number to a string.
1345  * @return String representation of this number.
1346  */
1347  std::string toString() const
1348  {
1349  return carl::toString(mValue);
1350  }
1351  };
1352 
1353  template<typename FloatType>
1354  inline bool is_integer(const FLOAT_T<FloatType>& in) {
1355  return carl::is_integer(in.value());
1356  }
1357 
1358  /**
1359  * Implements the division which assumes that there is no remainder.
1360  * @param _lhs
1361  * @param _rhs
1362  * @return Number which holds the result.
1363  */
1364  template<typename FloatType>
1366  {
1367  // TODO
1368  FLOAT_T<FloatType> result;
1369  result = _lhs / _rhs;
1370  return result;
1371  }
1372 
1373  /**
1374  * Implements the division with remainder.
1375  * @param _lhs
1376  * @param _rhs
1377  * @return Number which holds the result.
1378  */
1379  template<typename FloatType>
1381  {
1382  // TODO
1383  FLOAT_T<FloatType> result;
1384  result = _lhs / _rhs;
1385  return result;
1386  }
1387 
1388  /**
1389  * Casts the FLOAT_T to an arbitrary integer type which has a constructor for
1390  * a native int.
1391  * @param _float
1392  * @return Integer type which holds floor(_float).
1393  */
1394  template<typename Integer, typename FloatType>
1395  inline Integer to_int(const FLOAT_T<FloatType>& _float)
1396  {
1397  return carl::to_int<Integer>(_float.value());
1398  }
1399 
1400  template<typename FloatType>
1401  inline double to_double(const FLOAT_T<FloatType>& _float)
1402  {
1403  return double(_float);
1404  }
1405 
1406  /**
1407  * Method which returns the absolute value of the passed number.
1408  * @param _in Number.
1409  * @return Number which holds the result.
1410  */
1411  template<typename FloatType>
1413  {
1414  FLOAT_T<FloatType> result;
1415  _in.abs(result);
1416  return result;
1417  }
1418 
1419  /**
1420  * Method which returns the logarithm of the passed number.
1421  * @param _in Number.
1422  * @return Number which holds the result.
1423  */
1424  template<typename FloatType>
1426  {
1427  FLOAT_T<FloatType> result;
1428  _in.log(result);
1429  return result;
1430  }
1431 
1432  /**
1433  * Method which returns the square root of the passed number.
1434  * @param _in Number.
1435  * @return Number which holds the result.
1436  */
1437  template<typename FloatType>
1439  {
1440  FLOAT_T<FloatType> result;
1441  _in.sqrt(result);
1442  return result;
1443  }
1444 
1445  template<typename FloatType>
1446  inline std::pair<FLOAT_T<FloatType>, FLOAT_T<FloatType>> sqrt_safe(const FLOAT_T<FloatType>& _in)
1447  {
1448  return carl::sqrt_safe(_in.value());
1449  }
1450 
1451  template<typename FloatType>
1452  inline FLOAT_T<FloatType> pow(const FLOAT_T<FloatType>& _in, size_t _exp)
1453  {
1454  FLOAT_T<FloatType> result;
1455  _in.pow(result, _exp);
1456  return result;
1457  }
1458 
1459  template<typename FloatType>
1461  {
1462  FLOAT_T<FloatType> result;
1463  _in.sin(result);
1464  return result;
1465  }
1466 
1467  template<typename FloatType>
1469  {
1470  FLOAT_T<FloatType> result;
1471  _in.cos(result);
1472  return result;
1473  }
1474 
1475  template<typename FloatType>
1477  {
1478  FLOAT_T<FloatType> result;
1479  _in.asin(result);
1480  return result;
1481  }
1482 
1483  template<typename FloatType>
1485  {
1486  FLOAT_T<FloatType> result;
1487  _in.acos(result);
1488  return (result);
1489  }
1490 
1491  template<typename FloatType>
1493  {
1494  FLOAT_T<FloatType> result;
1495  _in.atan(result);
1496  return result;
1497  }
1498 
1499  /**
1500  * Method which returns the next smaller integer of this number or the number
1501  * itself, if it is already an integer.
1502  * @param _in Number.
1503  * @return Number which holds the result.
1504  */
1505  template<typename FloatType>
1507  {
1508  FLOAT_T<FloatType> result;
1509  _in.floor(result);
1510  return result;
1511  }
1512 
1513  /**
1514  * Method which returns the next larger integer of the passed number or the
1515  * number itself, if it is already an integer.
1516  * @param _in Number.
1517  * @return Number which holds the result.
1518  */
1519  template<typename FloatType>
1521  {
1522  FLOAT_T<FloatType> result;
1523  _in.ceil(result);
1524  return result;
1525  }
1526 
1527  template<>
1528  inline FLOAT_T<double> rationalize<FLOAT_T<double>>(double n)
1529  {
1530  return FLOAT_T<double>(n);
1531  }
1532 
1533  template<>
1534  inline FLOAT_T<float> rationalize<FLOAT_T<float>>(float n)
1535  {
1536  return FLOAT_T<float>(n);
1537  }
1538 
1539  template<>
1540  inline FLOAT_T<mpq_class> rationalize<FLOAT_T<mpq_class>>(double n)
1541  {
1542  return FLOAT_T<mpq_class>(carl::rationalize<mpq_class>(n));
1543  }
1544 
1545  #ifdef USE_CLN_NUMBERS
1546 
1547  template<>
1548  inline FLOAT_T<cln::cl_RA> rationalize<FLOAT_T<cln::cl_RA>>(double n)
1549  {
1550  return FLOAT_T<cln::cl_RA>(carl::rationalize<cln::cl_RA>(n));
1551  }
1552 
1553  /**
1554  * Implicitly converts the number to a rational and returns the denominator.
1555  * @param _in Number.
1556  * @return Cln interger which holds the result.
1557  */
1558  inline cln::cl_I get_denom(const FLOAT_T<cln::cl_RA>& _in)
1559  {
1560  return carl::get_denom(_in.value());
1561  }
1562 
1563  /**
1564  * Implicitly converts the number to a rational and returns the nominator.
1565  * @param _in Number.
1566  * @return Cln interger which holds the result.
1567  */
1568  inline cln::cl_I get_num(const FLOAT_T<cln::cl_RA>& _in)
1569  {
1570  return carl::get_num(_in.value());
1571  }
1572  #endif
1573  /**
1574  * Implicitly converts the number to a rational and returns the denominator.
1575  * @param _in Number.
1576  * @return GMP interger which holds the result.
1577  */
1578  inline mpz_class get_denom(const FLOAT_T<mpq_class>& _in)
1579  {
1580  return carl::get_denom(_in.value());
1581  }
1582 
1583  /**
1584  * Implicitly converts the number to a rational and returns the nominator.
1585  * @param _in Number.
1586  * @return GMP interger which holds the result.
1587  */
1588  inline mpz_class get_num(const FLOAT_T<mpq_class>& _in)
1589  {
1590  return carl::get_num(_in.value());
1591  }
1592 
1593  template<typename FloatType>
1594  inline bool is_zero(const FLOAT_T<FloatType>& _in) {
1595  return is_zero(_in.value());
1596  }
1597 
1598  template<typename FloatType>
1599  inline bool isInfinity(const FLOAT_T<FloatType>& _in) {
1600  return _in.value() == std::numeric_limits<FloatType>::infinity();
1601  }
1602 
1603  template<typename FloatType>
1604  inline bool isNan(const FLOAT_T<FloatType>& _in) {
1605  return _in.value() == std::numeric_limits<FloatType>::quiet_NaN();
1606  }
1607 
1608  template<>
1609  inline bool AlmostEqual2sComplement<FLOAT_T<double>>(const FLOAT_T<double>& A, const FLOAT_T<double>& B, unsigned maxUlps)
1610  {
1611  return AlmostEqual2sComplement<double>(A.value(), B.value(), maxUlps);
1612  }
1613 
1614 } // namespace
1615 
1616 namespace std{
1617 
1618  template<typename Number>
1619  struct hash<carl::FLOAT_T<Number>> {
1620  size_t operator()(const carl::FLOAT_T<Number>& _in) const {
1621  return hasher(_in.value());
1622  }
1623  private:
1624  std::hash<Number> hasher;
1625  };
1626 
1627  template<typename Number>
1628  class numeric_limits<carl::FLOAT_T<Number>>
1629  {
1630  public:
1631  static const bool is_specialized = true;
1632  static const bool is_signed = true;
1633  static const bool is_integer = false;
1634  static const bool is_exact = false;
1635  static const int radix = 2;
1636 
1637  static const bool has_infinity = true;
1638  static const bool has_quiet_NaN = true;
1639  static const bool has_signaling_NaN = true;
1640 
1641  static const bool is_iec559 = true; // = IEEE 754
1642  static const bool is_bounded = true;
1643  static const bool is_modulo = false;
1644  static const bool traps = true;
1645  static const bool tinyness_before = true;
1646 
1647  inline static carl::FLOAT_T<Number> (min)() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::min()); }
1648  inline static carl::FLOAT_T<Number> (max)() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::max()); }
1649  inline static carl::FLOAT_T<Number> lowest() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::lowest()); }
1650 
1651  inline static carl::FLOAT_T<Number> epsilon() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::epsilon()); }
1652 
1653  inline static carl::FLOAT_T<Number> round_error() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::round_error()); }
1654 
1655  inline static const carl::FLOAT_T<Number> infinity() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::infinity()); }
1656 
1657  inline static const carl::FLOAT_T<Number> quiet_NaN() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::quiet_NaN()); }
1658  inline static const carl::FLOAT_T<Number> signaling_NaN() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::signaling_NaN()); }
1659  inline static const carl::FLOAT_T<Number> denorm_min() { return carl::FLOAT_T<Number>(std::numeric_limits<Number>::denorm_min()); }
1660 
1661  static const int min_exponent = std::numeric_limits<Number>::min_exponent;
1662  static const int max_exponent = std::numeric_limits<Number>::max_exponent;
1663  static const int min_exponent10 = std::numeric_limits<Number>::min_exponent10;
1664  static const int max_exponent10 = std::numeric_limits<Number>::max_exponent10;
1665 
1666  inline static float_round_style round_style() { return std::numeric_limits<Number>::round_style; }
1667 
1668  inline static int digits() { return std::numeric_limits<Number>::digits; }
1669  inline static int digits10() { return std::numeric_limits<Number>::digits10; }
1670  inline static int max_digits10() { return std::numeric_limits<Number>::max_digits10; }
1671  };
1672 }
1673 
1674 
1675 #include "mpfr_float.tpp"
mpz_class Integer
States if a type represents a subset of all integers.
Definition: typetraits.h:219
carl is the main namespace for the library.
bool is_integer(const FLOAT_T< FloatType > &in)
Definition: FLOAT_T.h:1354
Interval< Number > acos(const Interval< Number > &i)
Definition: Trigonometry.h:58
FLOAT_T< FloatType > atan(const FLOAT_T< FloatType > &_in)
Definition: FLOAT_T.h:1492
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Definition: Interval.h:1535
FLOAT_T< FloatType > pow(const FLOAT_T< FloatType > &_in, size_t _exp)
Definition: FLOAT_T.h:1452
std::uint64_t uint
Definition: numbers.h:16
bool AlmostEqual2sComplement(const Number &A, const Number &B, unsigned=128)
Definition: FLOAT_T.h:83
std::string toString(Relation r)
Definition: Relation.h:73
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Definition: Interval.h:1511
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Definition: Interval.h:1523
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
Definition: Interval.h:1488
mpq_class rationalize< mpq_class >(float n)
Definition: operations.h:203
Interval< Number > tan(const Interval< Number > &i)
Definition: Trigonometry.h:34
FLOAT_T< FloatType > log(const FLOAT_T< FloatType > &_in)
Method which returns the logarithm of the passed number.
Definition: FLOAT_T.h:1425
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
FLOAT_T< FloatType > acos(const FLOAT_T< FloatType > &_in)
Definition: FLOAT_T.h:1484
Interval< Number > atanh(const Interval< Number > &i)
Definition: Trigonometry.h:142
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Definition: Interval.h:1453
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
Definition: Interval.h:1500
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
Definition: operations.h:60
Interval< Number > atan(const Interval< Number > &i)
Definition: Trigonometry.h:70
Interval< Number > cos(const Interval< Number > &i)
Definition: Trigonometry.h:22
Interval< Number > sqrt(const Interval< Number > &i)
Definition: Power.h:51
bool AlmostEqual2sComplement< double >(const double &A, const double &B, unsigned maxUlps)
Definition: FLOAT_T.h:89
T parse(const std::string &n)
FLOAT_T< FloatType > asin(const FLOAT_T< FloatType > &_in)
Definition: FLOAT_T.h:1476
BasicConstraint< ToPoly > convert(const typename ToPoly::ContextType &context, const BasicConstraint< FromPoly > &c)
Definition: Conversion.h:9
std::size_t precision_t
Definition: FLOAT_T.h:30
Interval< Number > asin(const Interval< Number > &i)
Definition: Trigonometry.h:46
FLOAT_T< FloatType > abs(const FLOAT_T< FloatType > &_in)
Method which returns the absolute value of the passed number.
Definition: FLOAT_T.h:1412
Interval< Number > div(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division which assumes that there is no remainder.
Definition: Interval.h:1476
Interval< Number > log(const Interval< Number > &i)
Definition: Exponential.h:22
FLOAT_T< FloatType > sqrt(const FLOAT_T< FloatType > &_in)
Method which returns the square root of the passed number.
Definition: FLOAT_T.h:1438
FLOAT_T< FloatType > ceil(const FLOAT_T< FloatType > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Definition: FLOAT_T.h:1520
bool is_integer(const Interval< Number > &n)
Definition: Interval.h:1445
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
Definition: operations.h:69
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
Definition: operations.h:113
bool isNan(const FLOAT_T< FloatType > &_in)
Definition: FLOAT_T.h:1604
std::int64_t sint
Definition: numbers.h:17
Interval< Number > sin(const Interval< Number > &i)
Definition: Trigonometry.h:10
Interval< Number > sinh(const Interval< Number > &i)
Definition: Trigonometry.h:82
Interval< Number > tanh(const Interval< Number > &i)
Definition: Trigonometry.h:106
Str2Double_Error
Definition: FLOAT_T.h:60
@ FLOAT_INCONVERTIBLE
Definition: FLOAT_T.h:60
@ FLOAT_SUCCESS
Definition: FLOAT_T.h:60
@ FLOAT_OVERFLOW
Definition: FLOAT_T.h:60
@ FLOAT_UNDERFLOW
Definition: FLOAT_T.h:60
std::pair< cln::cl_RA, cln::cl_RA > sqrt_safe(const cln::cl_RA &a)
Calculate the square root of a fraction.
Interval< Number > acosh(const Interval< Number > &i)
Definition: Trigonometry.h:130
Interval< Number > asinh(const Interval< Number > &i)
Definition: Trigonometry.h:118
bool isInfinity(const FLOAT_T< FloatType > &_in)
Definition: FLOAT_T.h:1599
Interval< Number > cosh(const Interval< Number > &i)
Definition: Trigonometry.h:94
Str2Double_Error str2double(double &d, char const *s)
Definition: FLOAT_T.h:62
Interval< Number > pow(const Interval< Number > &i, Integer exp)
Definition: Power.h:11
The class which contains the interval arithmetic including trigonometric functions.
Definition: Interval.h:134
Templated wrapper class which allows universal usage of different IEEE 754 implementations.
Definition: FLOAT_T.h:114
FLOAT_T & atanh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus tangent of this number and puts it into a passed resul...
Definition: FLOAT_T.h:908
FLOAT_T & sin_assign(CARL_RND=CARL_RND::N)
Assigns the number the sine of this number.
Definition: FLOAT_T.h:607
FLOAT_T & cos(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the cosine of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:644
FLOAT_T & floor(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the floor of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:921
FLOAT_T ei_log(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the logarith...
Definition: FLOAT_T.h:1118
bool operator==(const FLOAT_T &_rhs) const
Comparison operator for equality.
Definition: FLOAT_T.h:256
const FLOAT_T & ei_real(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the real par...
Definition: FLOAT_T.h:1043
bool operator>(int _rhs) const
Definition: FLOAT_T.h:283
FLOAT_T & cbrt(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Returns the cubic root of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:490
FLOAT_T & add_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for addition of two numbers, which assigns the result to the calling number.
Definition: FLOAT_T.h:341
FLOAT_T()
Default empty constructor, which initializes to zero.
Definition: FLOAT_T.h:124
bool operator!=(const FLOAT_T &_rhs) const
Comparison operator for inequality.
Definition: FLOAT_T.h:268
FLOAT_T & sinh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic sine of this number.
Definition: FLOAT_T.h:775
FLOAT_T & sinh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic sine of this number and puts it into a passed result paramet...
Definition: FLOAT_T.h:788
FLOAT_T & operator*=(const FLOAT_T &_rhs)
Operator which multiplicates this number by the righthand side.
Definition: FLOAT_T.h:1302
friend FLOAT_T operator*(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
Definition: FLOAT_T.h:1203
FLOAT_T & ceil_assign(CARL_RND=CARL_RND::N)
Assigns the number the ceiling of this number.
Definition: FLOAT_T.h:956
FLOAT_T & log_assign(CARL_RND=CARL_RND::N)
Assigns the number the logarithm of this number.
Definition: FLOAT_T.h:655
FLOAT_T ei_imag(const FLOAT_T &)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the imaginar...
Definition: FLOAT_T.h:1054
FLOAT_T & asinh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus sine of this number and puts it into a passed result p...
Definition: FLOAT_T.h:860
FLOAT_T ei_abs2(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the absolute...
Definition: FLOAT_T.h:1079
FLOAT_T & cosh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic cosine of this number and puts it into a passed result param...
Definition: FLOAT_T.h:812
FLOAT_T & floor_assign(CARL_RND=CARL_RND::N)
Assigns the number the floor of this number.
Definition: FLOAT_T.h:932
FLOAT_T ei_pow(const FLOAT_T &x, FLOAT_T y)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the power.
Definition: FLOAT_T.h:1158
FLOAT_T & cosh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic cosine of this number.
Definition: FLOAT_T.h:799
friend std::ostream & operator<<(std::ostream &ostr, const FLOAT_T &p)
Output stream operator for numbers of type FLOAT_T.
Definition: FLOAT_T.h:1020
FLOAT_T & operator=(const FLOAT_T &_rhs)=default
Assignment operator.
bool operator>=(const FLOAT_T &_rhs) const
Comparison operator for larger or equal than.
Definition: FLOAT_T.h:329
FLOAT_T ei_sin(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the sine.
Definition: FLOAT_T.h:1131
FLOAT_T & abs(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the absolute value of this number and puts it into a passed result paramete...
Definition: FLOAT_T.h:572
FLOAT_T & acosh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic arcus cosine of this number and puts it into a passed result...
Definition: FLOAT_T.h:884
FLOAT_T & cos_assign(CARL_RND=CARL_RND::N)
Assigns the number the cosine of this number.
Definition: FLOAT_T.h:631
double to_double(CARL_RND=CARL_RND::N) const
Function which converts the number to a double value.
Definition: FLOAT_T.h:968
FLOAT_T & cbrt_assign(CARL_RND=CARL_RND::N)
Function for the cubic root of the number, which assigns the result to the calling number.
Definition: FLOAT_T.h:476
FLOAT_T & root_assign(std::size_t, CARL_RND=CARL_RND::N)
Function for the nth root of the number, which assigns the result to the calling number.
Definition: FLOAT_T.h:504
FLOAT_T ei_cos(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the cosine.
Definition: FLOAT_T.h:1144
FLOAT_T(double _double, CARL_RND=CARL_RND::N)
Constructor, which takes a double as input and optional rounding, which can be used,...
Definition: FLOAT_T.h:134
FLOAT_T(const FLOAT_T &_float, CARL_RND=CARL_RND::N)
Copyconstructor which takes a FLOAT_T<FloatType> and optional rounding as input, which can be used,...
Definition: FLOAT_T.h:173
FLOAT_T & pow(FLOAT_T &_result, std::size_t _exp, CARL_RND=CARL_RND::N) const
Function which calculates the power of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:548
friend FLOAT_T operator+(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
Definition: FLOAT_T.h:1171
FLOAT_T & mul(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which multiplicates two numbers and puts the result in a third number passed as parameter.
Definition: FLOAT_T.h:408
FLOAT_T & sin(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the sine of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:620
FLOAT_T & ceil(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the ceiling of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:945
std::string toString() const
Method which converts this number to a string.
Definition: FLOAT_T.h:1347
bool operator<(unsigned _rhs) const
Definition: FLOAT_T.h:309
FLOAT_T & log(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the logarithm of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:668
FLOAT_T operator-()
Operator for unary negation of this number.
Definition: FLOAT_T.h:1290
FLOAT_T(sint _int, CARL_RND=CARL_RND::N)
Constructor, which takes an integer as input and optional rounding, which can be used,...
Definition: FLOAT_T.h:145
precision_t precision() const
If precision is used, this getter returns the acutal precision (default: 53 bit).
Definition: FLOAT_T.h:222
FLOAT_T & div(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which divides this number by the righthand side and puts the result in a third number passed...
Definition: FLOAT_T.h:436
FLOAT_T & tan(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the tangent of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:692
FLOAT_T & acosh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus cosine of this number.
Definition: FLOAT_T.h:871
FLOAT_T(unsigned _int, CARL_RND=CARL_RND::N)
Constructor, which takes an unsigned integer as input and optional rounding, which can be used,...
Definition: FLOAT_T.h:161
FLOAT_T & operator-=(const FLOAT_T &_rhs)
Operator which subtracts the righthand side from this.
Definition: FLOAT_T.h:1269
friend FLOAT_T operator/(const FLOAT_T &_lhs, const FLOAT_T &_rhs)
Operator for addition of two numbers.
Definition: FLOAT_T.h:1214
bool operator<=(const FLOAT_T &_rhs) const
Comparison operator for less or equal than.
Definition: FLOAT_T.h:319
bool operator<(int _rhs) const
Definition: FLOAT_T.h:304
FLOAT_T & sqrt_assign(CARL_RND=CARL_RND::N)
Function for the square root of the number, which assigns the result to the calling number.
Definition: FLOAT_T.h:449
FLOAT_T & pow_assign(std::size_t _exp, CARL_RND=CARL_RND::N)
Function for the nth power of the number, which assigns the result to the calling number.
Definition: FLOAT_T.h:534
FLOAT_T & atan(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus tangent of this number and puts it into a passed result parameter...
Definition: FLOAT_T.h:764
FLOAT_T & div_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for division of two numbers, which assigns the result to the calling number.
Definition: FLOAT_T.h:421
FLOAT_T & sub_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for subtraction of two numbers, which assigns the result to the calling number.
Definition: FLOAT_T.h:367
FLOAT_T & operator/=(const FLOAT_T &_rhs)
Operator which divides this number by the righthand side.
Definition: FLOAT_T.h:1325
FLOAT_T & operator+=(const FLOAT_T &_rhs)
Operator which adds the righthand side to this.
Definition: FLOAT_T.h:1247
const FloatType & value() const
Getter for the raw value contained.
Definition: FLOAT_T.h:213
FLOAT_T & asin(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus sine of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:716
FLOAT_T & tanh(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the hyperbolic tangent of this number and puts it into a passed result para...
Definition: FLOAT_T.h:836
FLOAT_T & tan_assign(CARL_RND=CARL_RND::N)
Assigns the number the tangent of this number.
Definition: FLOAT_T.h:679
bool operator>(const FLOAT_T &_rhs) const
Comparison operator for larger than.
Definition: FLOAT_T.h:278
FLOAT_T & exp_assign(CARL_RND=CARL_RND::N)
Assigns the number the exponential of this number.
Definition: FLOAT_T.h:583
FLOAT_T & tanh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic tangent of this number.
Definition: FLOAT_T.h:823
FLOAT_T & setPrecision(const precision_t &)
Allows to set the desired precision.
Definition: FLOAT_T.h:233
const FLOAT_T & ei_conj(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the complex ...
Definition: FLOAT_T.h:1032
FLOAT_T & acos_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus cosine of this number.
Definition: FLOAT_T.h:727
FLOAT_T & mul_assign(const FLOAT_T &_op2, CARL_RND=CARL_RND::N)
Function for multiplication of two numbers, which assigns the result to the calling number.
Definition: FLOAT_T.h:394
FLOAT_T & add(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which adds two numbers and puts the result in a third number passed as parameter.
Definition: FLOAT_T.h:354
FLOAT_T & exp(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the exponential of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:596
FLOAT_T & asinh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus sine of this number.
Definition: FLOAT_T.h:847
FLOAT_T & atanh_assign(CARL_RND=CARL_RND::N)
Assigns the number the hyperbolic arcus tangent of this number.
Definition: FLOAT_T.h:895
~FLOAT_T()=default
Destructor.
FLOAT_T & acos(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Function which calculates the arcus cosine of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:740
FLOAT_T(const std::string &_string, CARL_RND=CARL_RND::N)
Definition: FLOAT_T.h:192
FLOAT_T & asin_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus sine of this number.
Definition: FLOAT_T.h:703
friend FLOAT_T & operator--(FLOAT_T &_num)
Operator which decrements this number by one.
Definition: FLOAT_T.h:1236
FLOAT_T ei_sqrt(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the square r...
Definition: FLOAT_T.h:1092
FloatType mValue
Definition: FLOAT_T.h:115
FLOAT_T & sub(FLOAT_T &_result, const FLOAT_T &_op2, CARL_RND=CARL_RND::N) const
Function which subtracts the righthand side from this number and puts the result in a third number pa...
Definition: FLOAT_T.h:381
FLOAT_T ei_abs(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the absolute...
Definition: FLOAT_T.h:1065
FLOAT_T & atan_assign(CARL_RND=CARL_RND::N)
Assigns the number the arcus tangent of this number.
Definition: FLOAT_T.h:751
bool operator>(unsigned _rhs) const
Definition: FLOAT_T.h:288
FLOAT_T & sqrt(FLOAT_T &_result, CARL_RND=CARL_RND::N) const
Returns the square root of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:463
bool operator<(const FLOAT_T &_rhs) const
Comparison operator for less than.
Definition: FLOAT_T.h:299
friend FLOAT_T & operator++(FLOAT_T &_num)
Operator which increments this number by one.
Definition: FLOAT_T.h:1225
FLOAT_T & abs_assign(CARL_RND=CARL_RND::N)
Assigns the number the absolute value of this number.
Definition: FLOAT_T.h:559
FLOAT_T(int _int, CARL_RND=CARL_RND::N)
Definition: FLOAT_T.h:150
FLOAT_T ei_exp(const FLOAT_T &x)
Function required for extension of Eigen3 with FLOAT_T as a custom type which calculates the exponent...
Definition: FLOAT_T.h:1105
FLOAT_T(FLOAT_T &&_float, CARL_RND=CARL_RND::N) noexcept
Definition: FLOAT_T.h:176
FLOAT_T & root(FLOAT_T &, std::size_t, CARL_RND=CARL_RND::N) const
Function which calculates the nth root of this number and puts it into a passed result parameter.
Definition: FLOAT_T.h:520
FLOAT_T(FloatType val, CARL_RND=CARL_RND::N)
Constructor, which takes an arbitrary fp type as input and optional rounding, which can be used,...
Definition: FLOAT_T.h:186
Struct which holds the conversion operator for any two instanciations of FLOAT_T with different under...
Definition: FLOAT_T.h:46
FLOAT_T< T1 > operator()(const FLOAT_T< T2 > &_op2) const
Conversion operator for conversion of two instanciations of FLOAT_T with different underlying floatin...
Definition: FLOAT_T.h:53
size_t operator()(const carl::FLOAT_T< Number > &_in) const
Definition: FLOAT_T.h:1620
static const carl::FLOAT_T< Number > denorm_min()
Definition: FLOAT_T.h:1659
static const carl::FLOAT_T< Number > signaling_NaN()
Definition: FLOAT_T.h:1658
static float_round_style round_style()
Definition: FLOAT_T.h:1666
static carl::FLOAT_T< Number > round_error()
Definition: FLOAT_T.h:1653
static carl::FLOAT_T< Number > epsilon()
Definition: FLOAT_T.h:1651
static carl::FLOAT_T< Number > lowest()
Definition: FLOAT_T.h:1649
static const carl::FLOAT_T< Number > quiet_NaN()
Definition: FLOAT_T.h:1657
static const carl::FLOAT_T< Number > infinity()
Definition: FLOAT_T.h:1655