|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Exact sum of floating-point numbers. More...
#include <Negative_Cycles.H>
Public Types | |
| using | Component = exact_float_t< T > |
Type of the components (see exact_float_t). | |
Public Member Functions | |
| void | clear () noexcept |
| Set the value to zero; the storage is kept. | |
| bool | is_zero () const noexcept |
| True if the value is exactly zero. | |
| int | sign () const noexcept |
| Exact sign of the value: -1, 0 or 1. | |
| bool | add (const Component b) |
Add b exactly. | |
| bool | add (const Exact_Sum &x, const int exponent=0, const bool negate=false) |
Add the value of x, multiplied by 2^exponent and negated if asked. | |
| bool | add_multiple (const Exact_Sum &x, size_t factor, const bool negate=false) |
Add factor times the value of x, negated if asked. | |
| void | compress () |
| Rewrite the expansion so that its largest component approximates the value within one unit in its last place (Shewchuk's Compress). | |
| T | rounded () |
The value rounded to T: within one unit in the last place, zero only if the value is zero, and always with the exact sign. | |
| T | upper () |
The smallest number of T not below the value, or a slightly larger one; checked exactly, so it is a rigorous upper bound. | |
Static Private Member Functions | |
| static void | put (Array< Component > &a, const size_t i, const Component x) |
| static bool | grow (Array< Component > &a, size_t &n, const Component b) |
| static bool | grow_expansion (Array< Component > &a, size_t &n, const Component b) |
Private Attributes | |
| Array< Component > | h_ |
| Array< Component > | g_ |
| size_t | n_ = 0 |
Exact sum of floating-point numbers.
The value is kept as a nonoverlapping expansion (Shewchuk, "Adaptive
Precision Floating-Point Arithmetic and Fast Robust Geometric
Predicates", 1997): components of increasing magnitude whose exact sum is the value, no two of them sharing a bit position. Adding a number is error free, so the value is the exact sum of everything added; only a value beyond the range of the format cannot be represented, and add() reports it (as it may report a value within one unit in the last place of the largest finite number). The sign of the value is the sign of its largest component, so it is exact. Storage is reused across clear().
| T | Floating-point type of the numbers added. |
Definition at line 456 of file Negative_Cycles.H.
| using Aleph::negative_cycles_detail::Exact_Sum< T >::Component = exact_float_t<T> |
Type of the components (see exact_float_t).
Definition at line 460 of file Negative_Cycles.H.
|
inline |
Add b exactly.
| [in] | b | The number to add. |
Definition at line 540 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::grow(), Aleph::negative_cycles_detail::Exact_Sum< T >::h_, and Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::add(), Aleph::negative_cycles_detail::Exact_Sum< T >::add_multiple(), Aleph::negative_cycles_detail::Best_Cycle< Cost_Type >::offer(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
inline |
Add the value of x, multiplied by 2^exponent and negated if asked.
Exact unless it overflows.
| [in] | x | Another sum (not this one). |
| [in] | exponent | Power of two applied to every component. |
| [in] | negate | Whether to subtract instead of adding. |
Definition at line 552 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::add(), ah_invalid_argument_if, Aleph::negative_cycles_detail::Exact_Sum< T >::h_, and Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
|
inline |
Add factor times the value of x, negated if asked.
The factor is applied as a sum of powers of two, so it is exact.
| [in] | x | Another sum (not this one). |
| [in] | factor | Non-negative integer factor. |
| [in] | negate | Whether to subtract instead of adding. |
Definition at line 571 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::add(), and Aleph::and.
Referenced by Aleph::howard_detail::best_cycle_exactly().
|
inlinenoexcept |
Set the value to zero; the storage is kept.
Definition at line 517 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
Referenced by Aleph::howard_detail::best_cycle_exactly(), Aleph::negative_cycles_detail::Best_Cycle< Cost_Type >::offer(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
inline |
Rewrite the expansion so that its largest component approximates the value within one unit in its last place (Shewchuk's Compress).
Definition at line 581 of file Negative_Cycles.H.
References Aleph::Array< T >::append(), Aleph::negative_cycles_detail::Exact_Sum< T >::g_, Aleph::negative_cycles_detail::Exact_Sum< T >::h_, Aleph::negative_cycles_detail::Exact_Sum< T >::n_, Aleph::Array< T >::size(), and Aleph::negative_cycles_detail::two_sum().
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::rounded().
|
inlinestaticprivate |
Definition at line 484 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::grow_expansion().
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::add(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().
|
inlinestaticprivate |
Definition at line 497 of file Negative_Cycles.H.
References k, Aleph::negative_cycles_detail::Exact_Sum< T >::put(), and Aleph::negative_cycles_detail::two_sum().
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::grow().
|
inlinenoexcept |
True if the value is exactly zero.
Definition at line 523 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
|
inlinestaticprivate |
Definition at line 467 of file Negative_Cycles.H.
References Aleph::Array< T >::append(), and Aleph::Array< T >::size().
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::grow_expansion(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().
|
inline |
The value rounded to T: within one unit in the last place, zero only if the value is zero, and always with the exact sign.
Plus or minus infinity if the value does not fit T (or comes within one unit in the last place of its largest finite number), which callers must check when the components are wider than T (exact_float_t): add() does not report it then.
Definition at line 623 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::compress(), Aleph::negative_cycles_detail::Exact_Sum< T >::h_, and Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
Referenced by Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::total(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().
|
inlinenoexcept |
Exact sign of the value: -1, 0 or 1.
Definition at line 529 of file Negative_Cycles.H.
References Aleph::negative_cycles_detail::Exact_Sum< T >::h_, and Aleph::negative_cycles_detail::Exact_Sum< T >::n_.
Referenced by Aleph::howard_detail::best_cycle_exactly(), Aleph::negative_cycles_detail::Best_Cycle< Cost_Type >::offer(), and Aleph::negative_cycles_detail::Short_Cycle_Best< Cost_Type >::offer().
|
inline |
The smallest number of T not below the value, or a slightly larger one; checked exactly, so it is a rigorous upper bound.
A value above the largest finite T gives infinity, and so does a meaningless one (after an add() that returned false).
Definition at line 633 of file Negative_Cycles.H.
References Aleph::and, Aleph::negative_cycles_detail::Exact_Sum< T >::g_, Aleph::negative_cycles_detail::Exact_Sum< T >::grow(), Aleph::negative_cycles_detail::Exact_Sum< T >::h_, Aleph::negative_cycles_detail::Exact_Sum< T >::n_, Aleph::negative_cycles_detail::Exact_Sum< T >::put(), and Aleph::negative_cycles_detail::Exact_Sum< T >::rounded().
|
private |
Definition at line 464 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::compress(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().
|
private |
Definition at line 463 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::add(), Aleph::negative_cycles_detail::Exact_Sum< T >::add(), Aleph::negative_cycles_detail::Exact_Sum< T >::compress(), Aleph::negative_cycles_detail::Exact_Sum< T >::rounded(), Aleph::negative_cycles_detail::Exact_Sum< T >::sign(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().
|
private |
Definition at line 465 of file Negative_Cycles.H.
Referenced by Aleph::negative_cycles_detail::Exact_Sum< T >::add(), Aleph::negative_cycles_detail::Exact_Sum< T >::add(), Aleph::negative_cycles_detail::Exact_Sum< T >::clear(), Aleph::negative_cycles_detail::Exact_Sum< T >::compress(), Aleph::negative_cycles_detail::Exact_Sum< T >::is_zero(), Aleph::negative_cycles_detail::Exact_Sum< T >::rounded(), Aleph::negative_cycles_detail::Exact_Sum< T >::sign(), and Aleph::negative_cycles_detail::Exact_Sum< T >::upper().