GEOS  3.8.1
DD.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020 Crunchy Data
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
93 #ifndef GEOS_MATH_DD_H
94 #define GEOS_MATH_DD_H
95 
96 #include <cmath>
97 
98 namespace geos {
99 namespace math { // geos.math
100 
108 class GEOS_DLL DD {
109  private:
110  static constexpr double SPLIT = 134217729.0; // 2^27+1, for IEEE double
111  double hi;
112  double lo;
113 
114  int magnitude(double x) const;
115  int signum() const;
116  DD rint() const;
117 
118 
119  public:
120  DD(double p_hi, double p_lo) : hi(p_hi), lo(p_lo) {};
121  DD(double x) : hi(x), lo(0.0) {};
122  DD(const DD &dd) : hi(dd.hi), lo(dd.lo) {};
123  DD() : hi(0.0), lo(0.0) {};
124 
125  bool operator==(const DD &rhs) const
126  {
127  return hi == rhs.hi && lo == rhs.lo;
128  }
129 
130  bool operator!=(const DD &rhs) const
131  {
132  return hi != rhs.hi || lo != rhs.lo;
133  }
134 
135  bool operator<(const DD &rhs) const
136  {
137  return (hi < rhs.hi) || (hi == rhs.hi && lo < rhs.lo);
138  }
139 
140  bool operator<=(const DD &rhs) const
141  {
142  return (hi < rhs.hi) || (hi == rhs.hi && lo <= rhs.lo);
143  }
144 
145  bool operator>(const DD &rhs) const
146  {
147  return (hi > rhs.hi) || (hi == rhs.hi && lo > rhs.lo);
148  }
149 
150  bool operator>=(const DD &rhs) const
151  {
152  return (hi > rhs.hi) || (hi == rhs.hi && lo >= rhs.lo);
153  }
154 
155  friend DD operator+ (const DD &lhs, const DD &rhs);
156  friend DD operator+ (const DD &lhs, double rhs);
157  friend DD operator- (const DD &lhs, const DD &rhs);
158  friend DD operator- (const DD &lhs, double rhs);
159  friend DD operator* (const DD &lhs, const DD &rhs);
160  friend DD operator* (const DD &lhs, double rhs);
161  friend DD operator/ (const DD &lhs, const DD &rhs);
162  friend DD operator/ (const DD &lhs, double rhs);
163 
164  static DD determinant(const DD &x1, const DD &y1, const DD &x2, const DD &y2);
165  static DD determinant(double x1, double y1, double x2, double y2);
166  static DD abs(const DD &d);
167  static DD pow(const DD &d, int exp);
168  static DD trunc(const DD &d);
169 
170  bool isNaN() const;
171  bool isNegative() const;
172  bool isPositive() const;
173  bool isZero() const;
174  double doubleValue() const;
175  double ToDouble() const { return doubleValue(); }
176  int intValue() const;
177  DD negate() const;
178  DD reciprocal() const;
179  DD floor() const;
180  DD ceil() const;
181 
182  void selfAdd(const DD &d);
183  void selfAdd(double p_hi, double p_lo);
184  void selfAdd(double y);
185 
186  void selfSubtract(const DD &d);
187  void selfSubtract(double p_hi, double p_lo);
188  void selfSubtract(double y);
189 
190  void selfMultiply(double p_hi, double p_lo);
191  void selfMultiply(const DD &d);
192  void selfMultiply(double y);
193 
194  void selfDivide(double p_hi, double p_lo);
195  void selfDivide(const DD &d);
196  void selfDivide(double y);
197 };
198 
199 
200 } // namespace geos::math
201 } // namespace geos
202 
203 
204 #endif // GEOS_MATH_DD_H
geos::geom::operator!=
bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::operator==
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
geos::math::DD
Wrapper for DoubleDouble higher precision mathematics operations.
Definition: DD.h:132