GEOS 3.15.0dev
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#pragma once
94
95#include <cmath>
96#include <geos/export.h>
97
98namespace geos {
99namespace math { // geos.math
100
108class 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 void setNaN();
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() : hi(0.0), lo(0.0) {};
123
124 bool operator==(const DD &rhs) const
125 {
126 return hi == rhs.hi && lo == rhs.lo;
127 }
128
129 bool operator!=(const DD &rhs) const
130 {
131 return hi != rhs.hi || lo != rhs.lo;
132 }
133
134 bool operator<(const DD &rhs) const
135 {
136 return (hi < rhs.hi) || (hi == rhs.hi && lo < rhs.lo);
137 }
138
139 bool operator<=(const DD &rhs) const
140 {
141 return (hi < rhs.hi) || (hi == rhs.hi && lo <= rhs.lo);
142 }
143
144 bool operator>(const DD &rhs) const
145 {
146 return (hi > rhs.hi) || (hi == rhs.hi && lo > rhs.lo);
147 }
148
149 bool operator>=(const DD &rhs) const
150 {
151 return (hi > rhs.hi) || (hi == rhs.hi && lo >= rhs.lo);
152 }
153
154 friend GEOS_DLL DD operator+ (const DD &lhs, const DD &rhs);
155 friend GEOS_DLL DD operator+ (const DD &lhs, double rhs);
156 friend GEOS_DLL DD operator- (const DD &lhs, const DD &rhs);
157 friend GEOS_DLL DD operator- (const DD &lhs, double rhs);
158 friend GEOS_DLL DD operator* (const DD &lhs, const DD &rhs);
159 friend GEOS_DLL DD operator* (const DD &lhs, double rhs);
160 friend GEOS_DLL DD operator/ (const DD &lhs, const DD &rhs);
161 friend GEOS_DLL DD operator/ (const DD &lhs, double rhs);
162 friend GEOS_DLL DD operator- (const DD& x);
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 isInf() const;
171 bool isNaN() const;
172 bool isNegative() const;
173 bool isPositive() const;
174 bool isZero() const;
175 double doubleValue() const;
176 double ToDouble() const { return doubleValue(); }
177 int intValue() const;
178 DD negate() const;
179 DD reciprocal() const;
180 DD floor() const;
181 DD ceil() const;
182
183 void selfAdd(const DD &d);
184 void selfAdd(double p_hi, double p_lo);
185 void selfAdd(double y);
186
187 void selfSubtract(const DD &d);
188 void selfSubtract(double p_hi, double p_lo);
189 void selfSubtract(double y);
190
191 void selfMultiply(double p_hi, double p_lo);
192 void selfMultiply(const DD &d);
193 void selfMultiply(double y);
194
195 void selfDivide(double p_hi, double p_lo);
196 void selfDivide(const DD &d);
197 void selfDivide(double y);
198};
199
200
201} // namespace geos::math
202} // namespace geos
203
Wrapper for DoubleDouble higher precision mathematics operations.
Definition DD.h:108
Basic namespace for all GEOS functionalities.
Definition geos.h:38