GEOS 3.11.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#pragma once
94
95#include <cmath>
96
97namespace geos {
98namespace math { // geos.math
99
107class GEOS_DLL DD {
108 private:
109 static constexpr double SPLIT = 134217729.0; // 2^27+1, for IEEE double
110 double hi;
111 double lo;
112
113 int signum() const;
114 DD rint() const;
115
116
117 public:
118 DD(double p_hi, double p_lo) : hi(p_hi), lo(p_lo) {};
119 DD(double x) : hi(x), lo(0.0) {};
120 DD() : hi(0.0), lo(0.0) {};
121
122 bool operator==(const DD &rhs) const
123 {
124 return hi == rhs.hi && lo == rhs.lo;
125 }
126
127 bool operator!=(const DD &rhs) const
128 {
129 return hi != rhs.hi || lo != rhs.lo;
130 }
131
132 bool operator<(const DD &rhs) const
133 {
134 return (hi < rhs.hi) || (hi == rhs.hi && lo < rhs.lo);
135 }
136
137 bool operator<=(const DD &rhs) const
138 {
139 return (hi < rhs.hi) || (hi == rhs.hi && lo <= rhs.lo);
140 }
141
142 bool operator>(const DD &rhs) const
143 {
144 return (hi > rhs.hi) || (hi == rhs.hi && lo > rhs.lo);
145 }
146
147 bool operator>=(const DD &rhs) const
148 {
149 return (hi > rhs.hi) || (hi == rhs.hi && lo >= rhs.lo);
150 }
151
152 friend GEOS_DLL DD operator+ (const DD &lhs, const DD &rhs);
153 friend GEOS_DLL DD operator+ (const DD &lhs, double rhs);
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
161 static DD determinant(const DD &x1, const DD &y1, const DD &x2, const DD &y2);
162 static DD determinant(double x1, double y1, double x2, double y2);
163 static DD abs(const DD &d);
164 static DD pow(const DD &d, int exp);
165 static DD trunc(const DD &d);
166
167 bool isNaN() const;
168 bool isNegative() const;
169 bool isPositive() const;
170 bool isZero() const;
171 double doubleValue() const;
172 double ToDouble() const { return doubleValue(); }
173 int intValue() const;
174 DD negate() const;
175 DD reciprocal() const;
176 DD floor() const;
177 DD ceil() const;
178
179 void selfAdd(const DD &d);
180 void selfAdd(double p_hi, double p_lo);
181 void selfAdd(double y);
182
183 void selfSubtract(const DD &d);
184 void selfSubtract(double p_hi, double p_lo);
185 void selfSubtract(double y);
186
187 void selfMultiply(double p_hi, double p_lo);
188 void selfMultiply(const DD &d);
189 void selfMultiply(double y);
190
191 void selfDivide(double p_hi, double p_lo);
192 void selfDivide(const DD &d);
193 void selfDivide(double y);
194};
195
196
197} // namespace geos::math
198} // namespace geos
199
Wrapper for DoubleDouble higher precision mathematics operations.
Definition: DD.h:107
Basic namespace for all GEOS functionalities.
Definition: geos.h:39