GEOS  3.9.1dev
DD.h
Go to the documentation of this file.
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 signum() const;
115  DD rint() const;
116 
117 
118  public:
119  DD(double p_hi, double p_lo) : hi(p_hi), lo(p_lo) {};
120  DD(double x) : hi(x), lo(0.0) {};
121  DD() : hi(0.0), lo(0.0) {};
122 
123  bool operator==(const DD &rhs) const
124  {
125  return hi == rhs.hi && lo == rhs.lo;
126  }
127 
128  bool operator!=(const DD &rhs) const
129  {
130  return hi != rhs.hi || lo != rhs.lo;
131  }
132 
133  bool operator<(const DD &rhs) const
134  {
135  return (hi < rhs.hi) || (hi == rhs.hi && lo < rhs.lo);
136  }
137 
138  bool operator<=(const DD &rhs) const
139  {
140  return (hi < rhs.hi) || (hi == rhs.hi && lo <= rhs.lo);
141  }
142 
143  bool operator>(const DD &rhs) const
144  {
145  return (hi > rhs.hi) || (hi == rhs.hi && lo > rhs.lo);
146  }
147 
148  bool operator>=(const DD &rhs) const
149  {
150  return (hi > rhs.hi) || (hi == rhs.hi && lo >= rhs.lo);
151  }
152 
153  friend GEOS_DLL DD operator+ (const DD &lhs, const DD &rhs);
154  friend GEOS_DLL DD operator+ (const DD &lhs, double rhs);
155  friend GEOS_DLL DD operator- (const DD &lhs, const DD &rhs);
156  friend GEOS_DLL DD operator- (const DD &lhs, double rhs);
157  friend GEOS_DLL DD operator* (const DD &lhs, const DD &rhs);
158  friend GEOS_DLL DD operator* (const DD &lhs, double rhs);
159  friend GEOS_DLL DD operator/ (const DD &lhs, const DD &rhs);
160  friend GEOS_DLL DD operator/ (const DD &lhs, double rhs);
161 
162  static DD determinant(const DD &x1, const DD &y1, const DD &x2, const DD &y2);
163  static DD determinant(double x1, double y1, double x2, double y2);
164  static DD abs(const DD &d);
165  static DD pow(const DD &d, int exp);
166  static DD trunc(const DD &d);
167 
168  bool isNaN() const;
169  bool isNegative() const;
170  bool isPositive() const;
171  bool isZero() const;
172  double doubleValue() const;
173  double ToDouble() const { return doubleValue(); }
174  int intValue() const;
175  DD negate() const;
176  DD reciprocal() const;
177  DD floor() const;
178  DD ceil() const;
179 
180  void selfAdd(const DD &d);
181  void selfAdd(double p_hi, double p_lo);
182  void selfAdd(double y);
183 
184  void selfSubtract(const DD &d);
185  void selfSubtract(double p_hi, double p_lo);
186  void selfSubtract(double y);
187 
188  void selfMultiply(double p_hi, double p_lo);
189  void selfMultiply(const DD &d);
190  void selfMultiply(double y);
191 
192  void selfDivide(double p_hi, double p_lo);
193  void selfDivide(const DD &d);
194  void selfDivide(double y);
195 };
196 
197 
198 } // namespace geos::math
199 } // namespace geos
200 
201 
202 #endif // GEOS_MATH_DD_H
bool operator>=(const DD &rhs) const
Definition: DD.h:148
double ToDouble() const
Definition: DD.h:173
double hi
Definition: DD.h:111
#define GEOS_DLL
Definition: export.h:28
Wrapper for DoubleDouble higher precision mathematics operations.
Definition: DD.h:108
bool operator>(const DD &rhs) const
Definition: DD.h:143
double lo
Definition: DD.h:112
bool operator==(const DD &rhs) const
Definition: DD.h:123
bool operator!=(const DD &rhs) const
Definition: DD.h:128
Basic namespace for all GEOS functionalities.
bool operator<=(const DD &rhs) const
Definition: DD.h:138
bool operator<(const DD &rhs) const
Definition: DD.h:133
DD(double p_hi, double p_lo)
Definition: DD.h:119
DD(double x)
Definition: DD.h:120