Log-float

A class that represents numbers by their logarithms, so that (when used on top of floating-point numbers), they provide a large dynamic range. The main class, math::log_float, can only represent non-negative values; math::signed_log_float uses an explicit sign.

Classes

template <class ExponentType = double, class Policy = policy<>>
class math::log_float

A non-negative number that can be very close to zero or very large. It is stored as the logarithm of its value.

Floating-point numbers use a fixed-point significand and an integer exponent. This class, on the other hand, uses a significand fixed to 1, and a floating-point exponent, Exponent.

To store the value 0, -\infty is used.

To store a number that can be positive or negative, see signed_log_float. It is possible to interact with signed_log_float. Operations will return signed_log_float if the result can be negative, and log_float otherwise.

The Policy template argument is a Boost.Math policy for error handling. The policy is used for error handling in operations. Objects of this class that use different policies are not implicitly compatible and need to be converted explicitly first.

Some free functions that are available for floating-point numbers are provided: exp(), log(), pow(), sqrt(). exp_() is a shorthand that constructs a log_float from a float.

Unlike for floating-point numbers, functions that use a break-down in integer and fractional parts are not available, nor are trigonometric functions.

log_float supports Boost.Hash if boost/functional/hash.hpp is included. The hash value for a log_float is the same as the hash value of the signed_log_float with the same value.

See
signed_log_float
Templates
  • Exponent -

    The type to use to hold the exponent.

  • Policy -

    The Boost.Math policy that defines behaviour under domain errors, underflow errors, and overflow errors.

Public Type

typedef Exponent exponent_type

The type of the underlying exponent.

typedef Policy policy_type

The error policy.

Public Functions

log_float()

Construct with the value 0.

log_float(Exponent p)

Construct with value p.

log_float(Exponent e, as_exponent)

Construct with value exp(e).

log_float(log_float const & other)

Copy-construct.

template <typename OtherExponentType>
log_float(log_float< OtherExponentType, Policy > const & other)

Generalised copy construction with the same policy: implicit.

template <typename OtherExponentType, typename OtherPolicy>
log_float(log_float< OtherExponentType, OtherPolicy > const & other)

Generalised copy construction with a different policy: explicit.

template <typename OtherExponentType, typename OtherPolicy>
log_float(signed_log_float< OtherExponentType, OtherPolicy > const & other)

Copy-construct from signed_log_float. This is explicit.

Pre
“other” is positive.

Exponent exponent() const

Return
The exponent.

constexpr int sign() const

Return
The sign of the value (always +1 for log_float).

template <typename OtherExponentType>
log_float & operator*=(const log_float< OtherExponentType, Policy > & other)

Multiply with another log_float in place.

template <typename OtherExponentType>
log_float & operator/=(const log_float< OtherExponentType, Policy > & other)

Divide by another log_float in place.

template <typename OtherExponentType>
log_float & operator+=(const log_float< OtherExponentType, Policy > & other)

Add another log_float in place.

template <class ExponentType = double, class Policy = policy<>>
class math::signed_log_float

Generalisation of log_float that can contain negative values too.

It stores the logarithm of the absolute value of the contained number, and, separately, its sign.

See
log_float
Templates
  • Exponent -

    The type to use to hold the exponent.

  • Policy -

    The Boost.Math policy that defines behaviour under domain errors, underflow errors, and overflow errors.

Public Type

typedef Exponent exponent_type

The type of the underlying exponent.

typedef Policy policy_type

The error policy.

Public Functions

signed_log_float()

Construct with value 0.

signed_log_float(Exponent p)

Construct with value p.

signed_log_float(Exponent e, as_exponent)

Construct with value exp(e).

signed_log_float(Exponent e, int s, as_exponent)

Construct with value exp(e) and sign s.

Pre
s==-1 || s==+1

signed_log_float(signed_log_float const & other)

Copy-construct.

template <typename OtherExponentType>
signed_log_float(signed_log_float< OtherExponentType, Policy > const & other)

Generalised copy construction with the same policy: implicit.

template <typename OtherExponentType, typename OtherPolicy>
signed_log_float(signed_log_float< OtherExponentType, OtherPolicy > const & other)

Generalised copy construction with a different policy: explicit.

template <typename OtherExponentType>
signed_log_float(log_float< OtherExponentType, Policy > const & other)

Copy-construct from log_float with the same policy: implicit.

template <typename OtherExponentType, typename OtherPolicy>
signed_log_float(log_float< OtherExponentType, OtherPolicy > const & other)

Copy-construct from log_float with a different policy: explicit.

Exponent exponent() const

Return
The exponent.

int sign() const

Return
The sign (either -1 or +1).

template <class LogFloat, typename OtherExponentType, class Enable = typename boost::enable_if <std::is_same <typename LogFloat::policy_type, Policy>>::type>
signed_log_float & operator*=(detail::log_float_base< LogFloat, OtherExponentType > const & other)

Multiply with another log_float or signed_log_float in place.

template <class LogFloat, typename OtherExponentType, class Enable = typename boost::enable_if <std::is_same <typename LogFloat::policy_type, Policy>>::type>
signed_log_float & operator/=(detail::log_float_base< LogFloat, OtherExponentType > const & other)

Divide by another log_float or signed_log_float in place.

template <class LogFloat, typename OtherExponentType, class Enable = typename boost::enable_if <std::is_same <typename LogFloat::policy_type, Policy>>::type>
signed_log_float & operator+=(detail::log_float_base< LogFloat, OtherExponentType > const & other)

Add another log_float or signed_log_float in place.

template <class LogFloat, typename OtherExponentType, class Enable = typename boost::enable_if <std::is_same <typename LogFloat::policy_type, Policy>>::type>
signed_log_float & operator-=(detail::log_float_base< LogFloat, OtherExponentType > const & other)

Subtract another log_float or signed_log_float in place.

class math::as_exponent

Tag class to indicate that an argument is meant as an exponent.

Functions

template <typename Exponent, typename Enable = typename boost::enable_if < detail::valid_exponent_type <Exponent>>::type>
log_float< Exponent > exp_(Exponent const & d)

Construct a log_float instance from a value, using it as the value that is stored. This can be seen as a lazy implementation of computing the exponent of the value. Hence the spelling “exp_”.

template <typename Exponent, class Policy>
Exponent log(log_float< Exponent, Policy > const & p)

Return
The logarithm of the value contained in a log_float. Since log_float stores the contained value as a logarithm, this function is trivial.

template <typename LogFloat, class Exponent>
log_float< Exponent, typename LogFloat::policy_type > exp(detail::log_float_base< LogFloat, Exponent > const & w)

Exponentiate a log_float or signed_log_float. The result is always positive, so it is a log_float.

template <typename Exponent, typename Policy, typename Exponent2Type>
log_float< typename promote_args< Exponent, Exponent2Type >::type, Policy > pow(const log_float< Exponent, Policy > & w, Exponent2Type const & d)

Take a log_float to a power. This only takes a log_float, not a signed_log_float, so that this function is well-defined.

template <typename Exponent, class Policy>
log_float< Exponent, Policy > sqrt(log_float< Exponent, Policy > const & p)

Compute the square root.

Return
the square root of a log_float. This involves merely dividing the exponent by 2.

Table Of Contents

Previous topic

Mathematical tools library

Next topic

Magma

This Page