Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
multi_precision.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_NUMERICS_MULTI_PRECISION
41#define GEOGRAM_NUMERICS_MULTI_PRECISION
42
47#include <iostream>
48#include <sstream>
49#include <new>
50#include <math.h>
51
62
63namespace GEO {
64
65 extern bool expansion_initialized_;
66 extern double expansion_splitter_;
67 extern double expansion_epsilon_;
68
78 inline void two_sum(double a, double b, double& x, double& y) {
79 x = a + b;
80 double bvirt = x - a;
81 double avirt = x - bvirt;
82 double bround = b - bvirt;
83 double around = a - avirt;
84 y = around + bround;
85 }
86
96 inline void two_diff(double a, double b, double& x, double& y) {
97 x = a - b;
98 double bvirt = a - x;
99 double avirt = x + bvirt;
100 double bround = bvirt - b;
101 double around = a - avirt;
102 y = around + bround;
103 }
104
114 inline void fast_two_sum(double a, double b, double& x, double& y) {
115 x = a + b;
116 double bvirt = x - a;
117 y = b - bvirt;
118 }
119
129 inline void fast_two_diff(double a, double b, double& x, double& y) {
130 x = a - b;
131 double bvirt = a - x;
132 y = bvirt - b;
133 }
134
144 inline void split(double a, double& ahi, double& alo) {
145 geo_debug_assert(expansion_initialized_);
146 double c = expansion_splitter_ * a;
147 double abig = c - a;
148 ahi = c - abig;
149 alo = a - ahi;
150 }
151
161 inline void two_product(double a, double b, double& x, double& y) {
162#ifdef FP_FAST_FMA
163 // If the target processor supports the FMA (Fused Multiply Add)
164 // instruction, then the product of two doubles into a length-2
165 // expansion can be implemented as follows. Thanks to Marc Glisse
166 // for the information.
167 // Note: under gcc, automatic generations of fma() for a*b+c needs
168 // to be deactivated, using -ffp-contract=off, else it may break
169 // other functions such as fast_expansion_sum_zeroelim().
170 x = a*b;
171 y = fma(a,b,-x);
172#else
173 x = a * b;
174 double ahi, alo;
175 split(a, ahi, alo);
176 double bhi, blo;
177 split(b, bhi, blo);
178 double err1 = x - (ahi * bhi);
179 double err2 = err1 - (alo * bhi);
180 double err3 = err2 - (ahi * blo);
181 y = (alo * blo) - err3;
182#endif
183 }
184
193 inline void square(double a, double& x, double& y) {
194#ifdef FP_FAST_FMA
195 // If the target processor supports the FMA (Fused Multiply Add)
196 // instruction, then the product of two doubles into a length-2
197 // expansion can be implemented as follows. Thanks to Marc Glisse
198 // for the information.
199 // Note: under gcc, automatic generations of fma() for a*b+c needs
200 // to be deactivated, using -ffp-contract=off, else it may break
201 // other functions such as fast_expansion_sum_zeroelim().
202 x = a*a;
203 y = fma(a,a,-x);
204#else
205 x = a * a;
206 double ahi, alo;
207 split(a, ahi, alo);
208 double err1 = x - (ahi * ahi);
209 double err3 = err1 - ((ahi + ahi) * alo);
210 y = (alo * alo) - err3;
211#endif
212 }
213
214 /************************************************************************/
215
229 class GEOGRAM_API expansion {
230 public:
235 index_t length() const {
236 return length_;
237 }
238
245 return capacity_;
246 }
247
253 void set_length(index_t new_length) {
254 geo_debug_assert(new_length <= capacity());
255 length_ = new_length;
256 }
257
263 const double& operator[] (index_t i) const {
264 // Note: we allocate capacity+1 storage
265 // systematically, since basic functions
266 // may access one additional value (without
267 // using it)
268 geo_debug_assert(i <= capacity_);
269 return x_[i];
270 }
271
277 double& operator[] (index_t i) {
278 // Note: we allocate capacity+1 storage
279 // systematically, since basic functions
280 // may access one additional value (without
281 // using it)
282 geo_debug_assert(i <= capacity_);
283 return x_[i];
284 }
285
291 double* data() {
292 return x_;
293 }
294
300 const double* data() const {
301 return x_;
302 }
303
311 static size_t bytes(index_t capa) {
312 // --> 2*sizeof(double) because x_ is declared of size [2]
313 // to avoid compiler's warning.
314 // --> capa+1 to have an additional 'sentry' at the end
315 // because fast_expansion_sum_zeroelim() may access
316 // an entry past the end (without using it).
317 return
318 sizeof(expansion) - 2 * sizeof(double) +
319 (capa + 1) * sizeof(double);
320 }
321
331 static size_t bytes_on_stack(index_t capa) {
332#ifndef GEO_HAS_BIG_STACK
333 // Note: standard predicates need at least 512, hence the min.
334 // index_t(MAX_CAPACITY_ON_STACK) is necessary, else with
335 // MAX_CAPACITY_ON_STACK alone the compiler tries to generate a
336 // reference to NOT_IN_LIST resulting in a link error.
337 // (weird, even with constexpr, I do not understand...)
338 // Probably when the function excepts a *reference*
340 capa <= std::max(index_t(MAX_CAPACITY_ON_STACK),index_t(512))
341 );
342#endif
343 return bytes(capa);
344 }
345
356 length_(0),
357 capacity_(capa) {
358 }
359
367#ifdef CPPCHECK
368 // cppcheck does not understand that the result
369 // of alloca() is passed to the placement syntax
370 // of operator new.
372#else
373#define new_expansion_on_stack(capa) \
374 (new (alloca(expansion::bytes_on_stack(capa)))expansion(capa))
375#endif
376
384 void* addr = malloc(bytes(capa));
385 return new(addr)expansion(capa);
386 }
387
394 static inline void delete_expansion_on_heap(expansion* e) {
395 free(e);
396 }
397
398 // ========================== Initialization from doubles
399
405 expansion& assign(double a) {
406 set_length(1);
407 x_[0] = a;
408 return *this;
409 }
410
417 geo_debug_assert(capacity() >= rhs.length());
418 set_length(rhs.length());
419 for(index_t i=0; i<rhs.length(); ++i) {
420 x_[i] = rhs.x_[i];
421 }
422 return *this;
423 }
424
431 assign(rhs);
432 if(sign() == NEGATIVE) {
433 negate();
434 }
435 return *this;
436 }
437
448 static index_t sum_capacity(double a, double b) {
449 geo_argused(a);
450 geo_argused(b);
451 return 2;
452 }
453
464 expansion& assign_sum(double a, double b) {
465 set_length(2);
466 two_sum(a, b, x_[1], x_[0]);
467 return *this;
468 }
469
480 static index_t diff_capacity(double a, double b) {
481 geo_argused(a);
482 geo_argused(b);
483 return 2;
484 }
485
496 expansion& assign_diff(double a, double b) {
497 set_length(2);
498 two_diff(a, b, x_[1], x_[0]);
499 return *this;
500 }
501
512 static index_t product_capacity(double a, double b) {
513 geo_argused(a);
514 geo_argused(b);
515 return 2;
516 }
517
528 expansion& assign_product(double a, double b) {
529 set_length(2);
530 two_product(a, b, x_[1], x_[0]);
531 return *this;
532 }
533
543 static index_t square_capacity(double a) {
544 geo_argused(a);
545 return 2;
546 }
547
558 set_length(2);
559 square(a, x_[1], x_[0]);
560 return *this;
561 }
562
563 // ====== Initialization from expansion and double
564
575 static index_t sum_capacity(const expansion& a, double b) {
576 geo_argused(b);
577 return a.length() + 1;
578 }
579
590 expansion& assign_sum(const expansion& a, double b);
591
602 static index_t diff_capacity(const expansion& a, double b) {
603 geo_argused(b);
604 return a.length() + 1;
605 }
606
617 expansion& assign_diff(const expansion& a, double b);
618
629 static index_t product_capacity(const expansion& a, double b) {
630 geo_argused(b);
631 // TODO: implement special case where the double argument
632 // is a power of two.
633 return a.length() * 2;
634 }
635
646 expansion& assign_product(const expansion& a, double b);
647
648 // ========================== Initialization from expansions
649
658 static index_t sum_capacity(const expansion& a, const expansion& b) {
659 return a.length() + b.length();
660 }
661
673
684 const expansion& a, const expansion& b, const expansion& c
685 ) {
686 return a.length() + b.length() + c.length();
687 }
688
701 const expansion& a, const expansion& b, const expansion& c
702 );
703
715 const expansion& a, const expansion& b,
716 const expansion& c, const expansion& d
717 ) {
718 return a.length() + b.length() + c.length() + d.length();
719 }
720
734 const expansion& a, const expansion& b,
735 const expansion& c, const expansion& d
736 );
737
746 static index_t diff_capacity(const expansion& a, const expansion& b) {
747 return a.length() + b.length();
748 }
749
761
771 const expansion& a, const expansion& b
772 ) {
773 return a.length() * b.length() * 2;
774 }
775
787
798 const expansion& a, const expansion& b, const expansion& c
799 ) {
800 return a.length() * b.length() * c.length() * 4;
801 }
802
815 const expansion& a, const expansion& b, const expansion& c
816 );
817
826 if(a.length() == 2) {
827 return 6;
828 } // see two_square()
829 return a.length() * a.length() * 2;
830 }
831
842
843 // ====== Determinants =============================
844
853 const expansion& a11, const expansion& a12,
854 const expansion& a21, const expansion& a22
855 ) {
856 return
857 product_capacity(a11, a22) +
858 product_capacity(a21, a12);
859 }
860
872 const expansion& a11, const expansion& a12,
873 const expansion& a21, const expansion& a22
874 );
875
885 const expansion& a11, const expansion& a12, const expansion& a13,
886 const expansion& a21, const expansion& a22, const expansion& a23,
887 const expansion& a31, const expansion& a32, const expansion& a33
888 ) {
889 // Development w.r.t. first row
890 index_t c11_capa = det2x2_capacity(a22, a23, a32, a33);
891 index_t c12_capa = det2x2_capacity(a21, a23, a31, a33);
892 index_t c13_capa = det2x2_capacity(a21, a22, a31, a32);
893 return 2 * (
894 a11.length() * c11_capa +
895 a12.length() * c12_capa +
896 a13.length() * c13_capa
897 );
898 }
899
913 const expansion& a11, const expansion& a12, const expansion& a13,
914 const expansion& a21, const expansion& a22, const expansion& a23,
915 const expansion& a31, const expansion& a32, const expansion& a33
916 );
917
928 const expansion& a21, const expansion& a22, const expansion& a23,
929 const expansion& a31, const expansion& a32, const expansion& a33
930 ) {
931 return
932 det2x2_capacity(a22, a23, a32, a33) +
933 det2x2_capacity(a23, a21, a33, a31) +
934 det2x2_capacity(a21, a22, a31, a32);
935 }
936
949 const expansion& a21, const expansion& a22, const expansion& a23,
950 const expansion& a31, const expansion& a32, const expansion& a33
951 );
952
953 // ======= Geometry-specific initializations =======
954
964 return index_t(dim) * 6;
965 }
966
980 const double* p1, const double* p2, coord_index_t dim
981 );
982
992 return index_t(dim) * 8;
993 }
994
1008 const double* p1, const double* p2, const double* p0,
1009 coord_index_t dim
1010 );
1011
1012
1021 const expansion& x, const expansion& y, const expansion& z
1022 ) {
1024 }
1025
1035 const expansion& x, const expansion& y, const expansion& z
1036 );
1037
1038 // =============== some general purpose functions =========
1039
1046 static void initialize();
1047
1053 for(index_t i = 0; i < length_; ++i) {
1054 x_[i] = -x_[i];
1055 }
1056 return *this;
1057 }
1058
1067 // TODO: debug assert is_power_of_two(s)
1068 for(index_t i = 0; i < length_; ++i) {
1069 x_[i] *= s;
1070 }
1071 return *this;
1072 }
1073
1079 double estimate() const {
1080 double result = 0.0;
1081 for(index_t i = 0; i < length(); ++i) {
1082 result += x_[i];
1083 }
1084 return result;
1085 }
1086
1091 Sign sign() const {
1092 if(length() == 0) {
1093 return ZERO;
1094 }
1095 return geo_sgn(x_[length() - 1]);
1096 }
1097
1105 bool is_same_as(const expansion& rhs) const;
1106
1115 bool is_same_as(double rhs) const;
1116
1117
1122 Sign compare(const expansion& rhs) const;
1123
1128 Sign compare(double rhs) const;
1129
1136 bool equals(const expansion& rhs) const {
1137 return (compare(rhs) == ZERO);
1138 }
1139
1146 bool equals(double rhs) const {
1147 return (compare(rhs) == ZERO);
1148 }
1149
1155 std::ostream& show(std::ostream& out) const {
1156 out << "expansion[" << length() << "] = [";
1157 for(index_t i=0; i<length(); ++i) {
1158 out << (*this)[i] << " ";
1159 }
1160 out << "]";
1161 return out;
1162 }
1163
1168 std::string to_string() const {
1169 std::ostringstream out;
1170 show(out);
1171 return out.str();
1172 }
1173
1179 void optimize();
1180
1184 static void show_all_stats();
1185
1186 protected:
1197 index_t a_length, index_t b_length
1198 ) {
1199 return a_length * b_length * 2;
1200 }
1201
1212 const double* a, index_t a_length, const expansion& b
1213 );
1214
1218 expansion(const expansion& rhs) = delete;
1219
1223 expansion& operator= (const expansion& rhs) = delete;
1224
1225 private:
1226
1232#ifdef GEO_OS_APPLE
1233 static constexpr index_t MAX_CAPACITY_ON_STACK = 256;
1234#else
1235 static constexpr index_t MAX_CAPACITY_ON_STACK = 1024;
1236#endif
1237 index_t length_;
1238 index_t capacity_;
1239 double x_[2]; // x_ is in fact of size [capacity_]
1240
1241 friend class expansion_nt;
1242 };
1243
1244 // =============== arithmetic operations ===========================
1245
1258#define expansion_create(a) \
1259 new_expansion_on_stack(1)->assign(a)
1260
1261
1275#define expansion_abs(e) \
1276 new_expansion_on_stack(e.length())->assign_abs(e)
1277
1295#define expansion_sum(a, b) \
1296 new_expansion_on_stack( \
1297 expansion::sum_capacity(a, b) \
1298 )->assign_sum(a, b)
1299
1317#define expansion_sum3(a, b, c) \
1318 new_expansion_on_stack( \
1319 expansion::sum_capacity(a, b, c) \
1320 )->assign_sum(a, b, c)
1321
1341
1342#define expansion_sum4(a, b, c, d) \
1343 new_expansion_on_stack( \
1344 expansion::sum_capacity(a, b, c, d) \
1345 )->assign_sum(a, b, c, d)
1346
1364#define expansion_diff(a, b) \
1365 new_expansion_on_stack( \
1366 expansion::diff_capacity(a, b) \
1367 )->assign_diff(a, b)
1368
1386#define expansion_product(a, b) \
1387 new_expansion_on_stack( \
1388 expansion::product_capacity(a, b) \
1389 )->assign_product(a, b)
1390
1408#define expansion_product3(a, b, c) \
1409 new_expansion_on_stack( \
1410 expansion::product_capacity(a, b, c) \
1411 )->assign_product(a, b, c)
1412
1428#define expansion_square(a) \
1429 new_expansion_on_stack( \
1430 expansion::square_capacity(a) \
1431 )->assign_square(a)
1432
1433 // =============== determinants =====================================
1434
1448#define expansion_det2x2(a11, a12, a21, a22) \
1449 new_expansion_on_stack( \
1450 expansion::det2x2_capacity(a11, a12, a21, a22) \
1451 )->assign_det2x2(a11, a12, a21, a22)
1452
1469#define expansion_det3x3(a11, a12, a13, a21, a22, a23, a31, a32, a33) \
1470 new_expansion_on_stack( \
1471 expansion::det3x3_capacity(a11,a12,a13,a21,a22,a23,a31,a32,a33) \
1472 )->assign_det3x3(a11, a12, a13, a21, a22, a23, a31, a32, a33)
1473
1491#define expansion_det_111_2x3(a21, a22, a23, a31, a32, a33) \
1492 new_expansion_on_stack( \
1493 expansion::det_111_2x3_capacity(a21, a22, a23, a31, a32, a33) \
1494 )->assign_det_111_2x3(a21, a22, a23, a31, a32, a33)
1495
1496 // =============== geometric functions ==============================
1497
1514#define expansion_sq_dist(a, b, dim) \
1515 new_expansion_on_stack( \
1516 expansion::sq_dist_capacity(dim) \
1517 )->assign_sq_dist(a, b, dim)
1518
1537#define expansion_dot_at(a, b, c, dim) \
1538 new_expansion_on_stack( \
1539 expansion::dot_at_capacity(dim) \
1540 )->assign_dot_at(a, b, c, dim)
1541
1542
1558#define expansion_length2(x,y,z) \
1559 new_expansion_on_stack( \
1560 expansion::length2_capacity(x,y,z) \
1561 )->assign_length2(x,y,z)
1562
1563 /************************************************************************/
1564
1572 const expansion& a00,const expansion& a01,
1573 const expansion& a10,const expansion& a11
1574 );
1575
1583 const expansion& a00,const expansion& a01,const expansion& a02,
1584 const expansion& a10,const expansion& a11,const expansion& a12,
1585 const expansion& a20,const expansion& a21,const expansion& a22
1586 );
1587
1595 const expansion& a00,const expansion& a01,
1596 const expansion& a02,const expansion& a03,
1597 const expansion& a10,const expansion& a11,
1598 const expansion& a12,const expansion& a13,
1599 const expansion& a20,const expansion& a21,
1600 const expansion& a22,const expansion& a23,
1601 const expansion& a30,const expansion& a31,
1602 const expansion& a32,const expansion& a33
1603 );
1604
1605 /************************************************************************/
1606
1621 void GEOGRAM_API grow_expansion_zeroelim(
1622 const expansion& e, double b, expansion& h
1623 );
1624
1641 const expansion& e, double b, expansion& h
1642 );
1643
1660 const expansion& e, const expansion& f, expansion& h
1661 );
1662
1663
1679 const expansion& e, const expansion& f, expansion& h
1680 );
1681
1682 /************************************************************************/
1683}
1684
1685#endif
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:202
Represents numbers in arbitrary precision with a low-level API.
static index_t length2_capacity(const expansion &x, const expansion &y, const expansion &z)
Computes the required capacity to store the length of a 3d vector.
static index_t product_capacity(const expansion &a, const expansion &b)
Computes the required capacity of an expansion to store the exact product of two expansions.
void two_product(double a, double b, double &x, double &y)
Multiplies two doubles into a length 2 expansion.
expansion & assign_sum(const expansion &a, const expansion &b, const expansion &c, const expansion &d)
Assigns the sum of four expansions to this expansion (should not be used by client code).
static index_t product_capacity(double a, double b)
Computes the required capacity of an expansion to store the exact product of two doubles.
void two_diff(double a, double b, double &x, double &y)
Subtracts two doubles into a length 2 expansion.
#define new_expansion_on_stack(capa)
Allocates an expansion on the stack.
void split(double a, double &ahi, double &alo)
Splits a number into two components, ready for computing a product.
expansion & assign(const expansion &rhs)
Copies an expansion to this expansion.
static index_t sum_capacity(double a, double b)
Computes the required capacity to store the sum of two doubles.
static index_t sum_capacity(const expansion &a, const expansion &b, const expansion &c, const expansion &d)
Computes the required capacity of an expansion to store the exact sum of four expansions.
index_t length() const
Gets the length of this expansion.
expansion & assign_diff(const expansion &a, const expansion &b)
Assigns the difference between two expansions to this expansion (should not be used by client code).
expansion & assign_product(const expansion &a, const expansion &b, const expansion &c)
Assigns the product of three expansions to this expansion (should not be used by client code).
static index_t sub_product_capacity(index_t a_length, index_t b_length)
Computes the required capacity of an expansion to store an exact sub-product.
expansion & scale_fast(double s)
Multiplies this expansion by a power of two.
static void delete_expansion_on_heap(expansion *e)
Deallocates an expansion on the heap.
static index_t sum_capacity(const expansion &a, const expansion &b)
Computes the required capacity of an expansion to store the exact sum of two expansions.
static void initialize()
Initializes the expansion class.
static index_t sum_capacity(const expansion &a, const expansion &b, const expansion &c)
Computes the required capacity of an expansion to store the exact sum of three expansions.
void square(double a, double &x, double &y)
Squares a number into a length 2 expansion.
static index_t diff_capacity(double a, double b)
Computes the required capacity of an expansion to store the exact difference of two doubles.
bool equals(const expansion &rhs) const
Compares two expansions.
Sign compare(const expansion &rhs) const
Compares two expansions.
expansion & assign_det2x2(const expansion &a11, const expansion &a12, const expansion &a21, const expansion &a22)
Assigns a 2x2 determinant to this expansion (should not be used by client code).
expansion & assign_det_111_2x3(const expansion &a21, const expansion &a22, const expansion &a23, const expansion &a31, const expansion &a32, const expansion &a33)
Assigns a 3x3 determinant to this expansion where the first row is 1 1 1(should not be used by client...
expansion & assign_product(const expansion &a, double b)
Assigns the product between an expansion and a double to this expansion (should not be used by client...
index_t capacity() const
Gets the capacity of this expansion.
std::ostream & show(std::ostream &out) const
Displays all the components of this expansion (for debugging purposes).
expansion & assign_abs(const expansion &rhs)
Copies the absolute value of an expansion to this expansion.
expansion & assign_dot_at(const double *p1, const double *p2, const double *p0, coord_index_t dim)
Assigns the dot product of two vectors to this expansion (should not be used by client code).
static index_t sum_capacity(const expansion &a, double b)
Computes the required capacity of an expansion to store the exact sum of an expansion and a double.
double * data()
Low level access to the array of components.
expansion & assign_product(const expansion &a, const expansion &b)
Assigns the product of two expansions to this expansion (should not be used by client code).
static index_t square_capacity(const expansion &a)
Computes the required capacity of an expansion to store the exact square of an expansion.
expansion & assign_sub_product(const double *a, index_t a_length, const expansion &b)
Assigns a sub-product to this expansion.
const double * data() const
Low level access to the array of components.
expansion & assign_diff(double a, double b)
Assigns the difference of two doubles to this expansion (should not be used by client code).
expansion & assign_square(const expansion &a)
Assigns the product of an expansions to this expansion (should not be used by client code).
void set_length(index_t new_length)
Changes the length of an expansion.
expansion & assign_det3x3(const expansion &a11, const expansion &a12, const expansion &a13, const expansion &a21, const expansion &a22, const expansion &a23, const expansion &a31, const expansion &a32, const expansion &a33)
Assigns a 3x3 determinant to this expansion (should not be used by client code).
bool is_same_as(double rhs) const
Compares an expansion and a double bit-by-bit.
expansion & assign(double a)
Assigns a number to this expansion.
expansion & assign_diff(const expansion &a, double b)
Assigns the difference between an expansion and a double to this expansion (should not be used by cli...
expansion & assign_sum(const expansion &a, double b)
Assigns the sum of an expansion and a double to this expansion (should not be used by client code).
static index_t det_111_2x3_capacity(const expansion &a21, const expansion &a22, const expansion &a23, const expansion &a31, const expansion &a32, const expansion &a33)
Computes the required capacity of an expansion to store an exact 3x3 determinant where the first row ...
expansion & assign_sum(double a, double b)
Assigns the sum of two doubles to this expansion (should not be used by client code).
bool equals(double rhs) const
Compares an expansion and a double.
static index_t det2x2_capacity(const expansion &a11, const expansion &a12, const expansion &a21, const expansion &a22)
Computes the required capacity of an expansion to store an exact 2x2 determinant.
expansion(index_t capa)
Client code should not use this constructor.
static index_t diff_capacity(const expansion &a, const expansion &b)
Computes the required capacity of an expansion to store the exact difference of two expansions.
expansion(const expansion &rhs)=delete
Expansions cannot be copied.
static size_t bytes_on_stack(index_t capa)
Computes the amount of memory required to store an expansion on the stack.
static index_t product_capacity(const expansion &a, double b)
Computes the required capacity of an expansion to store the exact product between an expansion and a ...
static index_t sq_dist_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact squared distance between two points...
expansion & negate()
Changes the sign of an expansion.
static index_t product_capacity(const expansion &a, const expansion &b, const expansion &c)
Computes the required capacity of an expansion to store the exact product of three expansions.
static size_t bytes(index_t capa)
Computes the amount of memory required to store an expansion.
static index_t det3x3_capacity(const expansion &a11, const expansion &a12, const expansion &a13, const expansion &a21, const expansion &a22, const expansion &a23, const expansion &a31, const expansion &a32, const expansion &a33)
Computes the required capacity of an expansion to store an exact 3x3 determinant.
double estimate() const
Computes an approximation of the stored value in this expansion.
static index_t square_capacity(double a)
Computes the required capacity of an expansion to store the exact square of a double.
expansion & assign_sum(const expansion &a, const expansion &b)
Assigns the sum of two expansions to this expansion (should not be used by client code).
static void show_all_stats()
Show global statistics.
static index_t dot_at_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact dot product between two vectors.
bool is_same_as(const expansion &rhs) const
Compares two expansions bit-by-bit.
expansion & assign_sum(const expansion &a, const expansion &b, const expansion &c)
Assigns the sum of three expansions to this expansion (should not be used by client code).
static index_t diff_capacity(const expansion &a, double b)
Computes the required capacity of an expansion to store the exact difference between an expansion and...
std::string to_string() const
Gets a string representation of this expansion.
static expansion * new_expansion_on_heap(index_t capa)
Allocates an expansion on the heap.
expansion & assign_length2(const expansion &x, const expansion &y, const expansion &z)
Assigns the length of a vector to this expansion (should not be used by client code)....
expansion & assign_square(double a)
Assigns the square of a double to this expansion (should not be used by client code).
expansion & assign_sq_dist(const double *p1, const double *p2, coord_index_t dim)
Assigns the squared distance between two points to this expansion (should not be used by client code)...
void two_sum(double a, double b, double &x, double &y)
Sums two doubles into a length 2 expansion.
void optimize()
Optimizes the internal representation without changing the represented value.
expansion & assign_product(double a, double b)
Assigns the product of two doubles to this expansion (should not be used by client code).
Sign compare(double rhs) const
Compares two expansions.
Sign sign() const
Gets the sign of the expansion.
Common include file, providing basic definitions. Should be included before anything else by all head...
Types and functions for memory manipulation.
Global Vorpaline namespace.
void scale_expansion_zeroelim(const expansion &e, double b, expansion &h)
Multiplies an expansion by a scalar, eliminating zero components from the output expansion.
void grow_expansion_zeroelim(const expansion &e, double b, expansion &h)
Adds a scalar to an expansion, eliminating zero components from the output expansion.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition argused.h:60
void fast_two_diff(double a, double b, double &x, double &y)
Computes the difference of two doubles into a length 2 expansion.
void fast_expansion_sum_zeroelim(const expansion &e, const expansion &f, expansion &h)
Sums two expansions, eliminating zero components from the output expansion (sets h = e + f).
Sign geo_sgn(const T &x)
Gets the sign of a value.
Definition numeric.h:111
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:341
void fast_expansion_diff_zeroelim(const expansion &e, const expansion &f, expansion &h)
Computes the difference of two expansions, eliminating zero components from the output expansion.
Sign
Integer constants that represent the sign of a value.
Definition numeric.h:73
@ ZERO
Definition numeric.h:77
@ NEGATIVE
Definition numeric.h:75
void fast_two_sum(double a, double b, double &x, double &y)
Computes the sum of two doubles into a length 2 expansion.
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:375
Sign sign_of_expansion_determinant(const expansion &a00, const expansion &a01, const expansion &a10, const expansion &a11)
Computes the sign of a 2x2 determinant.
Types and functions for numbers manipulation.