| 1 | #cxx . . $ `<file>/dwsys/ExtendedReal.h`/ifndef _ExtendedReal_h_ |
| 2 | #define _ExtendedReal_h_cxx . . $ `dwsys/ExtendedReal.h:2:9`! |
| 3 | /* ExtendedReal.h |
| 4 | * |
| 5 | * Copyright (C) 2025 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | We extend the set of real numbers into a non-Archimedian ordered field by adding infinitesimals. |
| 23 | A positive infinitesimal number eps is smaller than any positive real number. |
| 24 | The predicate a < b, where a and b are reals, is affected by adding infinitesimals in the following way: |
| 25 | The test might become a + eps**2**i) < b + eps**2**j (a**b**c is shorthand notation for power (a, power (b,c))). |
| 26 | Assume without loss of generality that 0 < i <j. |
| 27 | If a != b, then if a < b is true, then also a + eps**i < b + eps**j. Adding the infinitesimal didn't |
| 28 | change the result. However, if a == b than the infinitisimals breaks the tie. |
| 29 | So adding infinitesimals to a and b we need to change the predicate from (a < b) to (if a!=b ? a < b : i > j). |
| 30 | |
| 31 | Our simple implementation is the ExtendedReal with consists of the struct {double real; integer extension;} |
| 32 | 'extension' represent the infinitesimal power (eps, power (2,extension)). |
| 33 | |
| 34 | An ExtendedReal can be copied but should not be saved in a file. |
| 35 | */ |
| 36 | |
| 37 | #include "Data.h"cxx . . $ `<file>/sys/Data.h`/ |
| 38 | |
| 39 | #include "ExtendedReal_def.h"cxx . . $ `<file>/dwsys/ExtendedReal_def.h`/ |
| 40 | |
| 41 | template <typename structT> |
| 42 | autoVECcxx . . $ autoVEC# vector_to_VECcxx . . $ vector_to_VEC(372e1da24e3484d8). (vectorcxx . . $ vector#<structT> v); |
| 43 | |
| 44 | /* |
| 45 | Put the kth smallest element at position k |
| 46 | */ |
| 47 | template <typename structT> |
| 48 | void NUMselectcxx . . $ NUMselect(790b03410319325e). (vectorcxx . . $ vector#<structT> const& v, integercxx . . $ integer# kth_asIfSorted); |
| 49 | |
| 50 | structExtendedRealcxx . . $ structExtendedReal#& NUMget_kth_inplacecxx . . $ NUMget_kth_inplace(4fa6b2a6b99885a1). (vectorcxx . . $ vector#<structExtendedRealcxx . . $ structExtendedReal#> const& v, integercxx . . $ integer# kth_asIfSorted); |
| 51 | structExtendedRealcxx . . $ structExtendedReal#& NUMget_kthcxx . . $ NUMget_kth(8a35bdc3fc16186f). (constvectorviewcxx . . $ constvectorview#<structExtendedRealcxx . . $ structExtendedReal#> const& v, integercxx . . $ integer# kth_asIfSorted); |
| 52 | |
| 53 | structExtendedRealcxx . . $ structExtendedReal#& NUMquantilecxx . . $ NUMquantile(8cdc0f0ab77be023). (constvectorviewcxx . . $ constvectorview#<structExtendedRealcxx . . $ structExtendedReal#> const& v, double factor); |
| 54 | structExtendedRealcxx . . $ structExtendedReal#& NUMquantile_inplacecxx . . $ NUMquantile_inplace(913a9503af7d861f). (vectorcxx . . $ vector#<structExtendedRealcxx . . $ structExtendedReal#> const& v, double factor); |
| 55 | |
| 56 | #endif /* _ExtendedReal_h_ */ |