Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::negative_cycles_detail::Exact_Sum< T > Class Template Reference

Exact sum of floating-point numbers. More...

#include <Negative_Cycles.H>

Inheritance diagram for Aleph::negative_cycles_detail::Exact_Sum< T >:
[legend]
Collaboration diagram for Aleph::negative_cycles_detail::Exact_Sum< T >:
[legend]

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
 

Detailed Description

template<typename T>
class Aleph::negative_cycles_detail::Exact_Sum< T >

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().

Template Parameters
TFloating-point type of the numbers added.

Definition at line 456 of file Negative_Cycles.H.

Member Typedef Documentation

◆ Component

template<typename T >
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.

Member Function Documentation

◆ add() [1/2]

template<typename T >
bool Aleph::negative_cycles_detail::Exact_Sum< T >::add ( const Component  b)
inline

Add b exactly.

Parameters
[in]bThe number to add.
Returns
False if the value overflowed the components (it may also be returned for a value within one unit in the last place of their largest finite number); the value is then meaningless.

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().

◆ add() [2/2]

template<typename T >
bool Aleph::negative_cycles_detail::Exact_Sum< T >::add ( const Exact_Sum< T > &  x,
const int  exponent = 0,
const bool  negate = false 
)
inline

Add the value of x, multiplied by 2^exponent and negated if asked.

Exact unless it overflows.

Parameters
[in]xAnother sum (not this one).
[in]exponentPower of two applied to every component.
[in]negateWhether to subtract instead of adding.
Returns
False on overflow.

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_.

◆ add_multiple()

template<typename T >
bool Aleph::negative_cycles_detail::Exact_Sum< T >::add_multiple ( const Exact_Sum< T > &  x,
size_t  factor,
const bool  negate = false 
)
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.

Parameters
[in]xAnother sum (not this one).
[in]factorNon-negative integer factor.
[in]negateWhether to subtract instead of adding.
Returns
False on overflow.

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().

◆ clear()

◆ compress()

template<typename T >
void Aleph::negative_cycles_detail::Exact_Sum< T >::compress ( )
inline

◆ grow()

template<typename T >
static bool Aleph::negative_cycles_detail::Exact_Sum< T >::grow ( Array< Component > &  a,
size_t &  n,
const Component  b 
)
inlinestaticprivate

◆ grow_expansion()

template<typename T >
static bool Aleph::negative_cycles_detail::Exact_Sum< T >::grow_expansion ( Array< Component > &  a,
size_t &  n,
const Component  b 
)
inlinestaticprivate

◆ is_zero()

template<typename T >
bool Aleph::negative_cycles_detail::Exact_Sum< T >::is_zero ( ) const
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_.

◆ put()

template<typename T >
static void Aleph::negative_cycles_detail::Exact_Sum< T >::put ( Array< Component > &  a,
const size_t  i,
const Component  x 
)
inlinestaticprivate

◆ rounded()

template<typename T >
T Aleph::negative_cycles_detail::Exact_Sum< T >::rounded ( )
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().

◆ sign()

◆ upper()

template<typename T >
T Aleph::negative_cycles_detail::Exact_Sum< T >::upper ( )
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().

Member Data Documentation

◆ g_

◆ h_

◆ n_


The documentation for this class was generated from the following file: