Public Types | Static Public Member Functions | List of all members
fcl::constants< S > Struct Template Reference

#include <constants.h>

Public Types

typedef detail::ScalarTrait< S >::type Real
 

Static Public Member Functions

static constexpr Real eps ()
 Returns ε for the precision of the underlying scalar type. More...
 
static Real eps_12 ()
 Returns ε^(1/2) for the precision of the underlying scalar type. More...
 
static Real eps_34 ()
 Returns ε^(3/4) for the precision of the underlying scalar type. More...
 
static Real eps_78 ()
 Returns ε^(7/8) for the precision of the underlying scalar type. More...
 
static Real gjk_default_tolerance ()
 
static constexpr S phi ()
 The golden ratio. More...
 
static constexpr S pi ()
 The mathematical constant pi. More...
 

Detailed Description

template<typename S>
struct fcl::constants< S >

A collection of scalar-dependent constants. This provides the ability to get mathematical constants and tolerance values that are appropriately scaled and typed to the scalar type S.

Constants pi() and phi() are returned in the literal scalar type S. In other words, if S is an AutoDiffScalar<...>, then the value of pi and phi are likewise AutoDiffScalar<...> typed.

Tolerances (e.g., eps() and its variants) are always provided in the scalar's numerical representation. In other words, if S is a double or float, the tolerances are given as double and float, respectively. For AutoDiffScalar it is more interesting. The AutoDiffScalar has an underlying numerical representation (e.g., AutoDiffScalar<Matrix<double, 1, 3>> has a double). It is the type of this underlying numerical representation that is provided by the tolerance functions.

This is designed to specifically work with float, double, long double, and corresponding AutoDiffScalar types. However, custom scalars will also work provided that the scalar type provides a class member type Real which must be one of long double, double, or float. E.g.,

struct MyScalar {
public:
typedef double Real;
...
};
Note
The tolerance values provided are defined so as to provide varying precision that scales with the underlying numerical type. The following contrast will make it clear.
S local_eps = 10 * std::numeric_limit<S>::epsilon(); // DON'T DO THIS!

The above example shows a common but incorrect method for defining a local epsilon. It defines it as being an order of magnitude larger (base 10) than the machine epsilon for S. However, if S is a float, its epsilon is essentially 1e-7. A full decimal digit of precision is 1/7th of the available digits. In contrast, double epsilon is approximately 2e-16. Throwing away a digit there reduces the precision by only 1/16th. This technique disproportionately punishes lower-precision numerical representations. Instead, by raising epsilon to a fractional power, we scale the precision. Roughly, ε^(1/2) gives us half the precision (3.5e-4 for floats and 1.5e-8 for doubles). Similarly powers of 3/4 and 7/8 gives us three quarters and 7/8ths of the bits of precision. By defining tolerances in this way, one can get some fraction of machine precision, regardless of the choice of numeric type.

Template Parameters
SThe scalar type for which constant values will be retrieved.

Definition at line 129 of file constants.h.

Member Typedef Documentation

◆ Real

template<typename S >
typedef detail::ScalarTrait<S>::type fcl::constants< S >::Real

Definition at line 131 of file constants.h.

Member Function Documentation

◆ eps()

template<typename S >
static constexpr Real fcl::constants< S >::eps ( )
inlinestaticconstexpr

Returns ε for the precision of the underlying scalar type.

Definition at line 151 of file constants.h.

◆ eps_12()

template<typename S >
static Real fcl::constants< S >::eps_12 ( )
inlinestatic

Returns ε^(1/2) for the precision of the underlying scalar type.

Definition at line 176 of file constants.h.

◆ eps_34()

template<typename S >
static Real fcl::constants< S >::eps_34 ( )
inlinestatic

Returns ε^(3/4) for the precision of the underlying scalar type.

Definition at line 170 of file constants.h.

◆ eps_78()

template<typename S >
static Real fcl::constants< S >::eps_78 ( )
inlinestatic

Returns ε^(7/8) for the precision of the underlying scalar type.

Definition at line 164 of file constants.h.

◆ gjk_default_tolerance()

template<typename S >
static Real fcl::constants< S >::gjk_default_tolerance ( )
inlinestatic

Defines the default accuracy for gjk and epa tolerance. It is defined as ε^(7/8) – where ε is the machine precision epsilon for the in-use Real. The value is a much smaller epsilon for doubles than for floats (2e-14 vs 9e-7, respectively). The choice of ε^(7/8) as the default GJK tolerance reflects a tolerance that is a slightly tighter bound than the historical value of 1e-6 used for 32-bit floats.

Definition at line 145 of file constants.h.

◆ phi()

template<typename S >
static constexpr S fcl::constants< S >::phi ( )
inlinestaticconstexpr

The golden ratio.

Definition at line 137 of file constants.h.

◆ pi()

template<typename S >
static constexpr S fcl::constants< S >::pi ( )
inlinestaticconstexpr

The mathematical constant pi.

Definition at line 134 of file constants.h.


The documentation for this struct was generated from the following file:
epsilon
S epsilon()
Definition: test_fcl_simple.cpp:56
fcl::constants::Real
detail::ScalarTrait< S >::type Real
Definition: constants.h:131


fcl
Author(s):
autogenerated on Tue Dec 5 2023 03:40:50