SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
Utility

Provides additional utility functionality used by multiple modules. More...

+ Collaboration diagram for Utility:

Modules

 Bloom Filter
 Provides seqan3:bloom_filter.
 
 Builtin Character Operations
 Provides various operations on character types.
 
 Concept
 Provides various general purpose concepts.
 
 Container
 Provides various general purpose container and concepts.
 
 Range
 The range module provides general purpose range concepts.
 
 Tuple
 Additional helper utilities for "tuple" types like std::tuple, std::pair, seqan3::pod_tuple that are not specific to a SeqAn module.
 
 Type List
 Provides seqan3::type_list and metaprogramming utilities for working on type lists.
 
 Type Pack
 Provides metaprogramming utilities for working on template parameter packs.
 
 Type Traits
 Provides various type traits and their shortcuts.
 
 Views
 Views are "lazy range combinators" that offer modified views onto other ranges.
 

Functions

template<typename base_t , std::unsigned_integral exp_t>
requires (std::same_as<base_t, uint64_t> || std::same_as<base_t, int64_t>)
base_t seqan3::pow (base_t base, exp_t exp)
 Computes the value of base raised to the power exp.
 

Detailed Description

Provides additional utility functionality used by multiple modules.

The utility module contains concepts, functions, traits and classes that are independent of the remaining modules in SeqAn. These implementations are considered external functionality, i.e. they could have been outsourced into their own libraries.

The utility module has no dependency to any other module except the Core module.

Function Documentation

◆ pow()

template<typename base_t , std::unsigned_integral exp_t>
requires (std::same_as<base_t, uint64_t> || std::same_as<base_t, int64_t>)
base_t seqan3::pow ( base_t  base,
exp_t  exp 
)

Computes the value of base raised to the power exp.

Parameters
[in]baseThe base to compute the power for.
[in]expThe power to raise base to.
Returns
\( base^{exp} \).
Exceptions
std::overflow_errorif an overflow occurs (Only in Debug build).
std::underflow_errorif an underflow occurs (Only in Debug build).
See also
https://en.cppreference.com/w/cpp/numeric/math/pow

The difference to std::pow is that the powers of an integer base are computed exact (without precision loss due to promoting to double) iff exp_t models std::unsigned_integral and

  • base_t models std::unsigned_integral (returns uint64_t)
  • base_t models std::integral, but not std::unsigned_integral (returns int64_t)

In all other cases the return value and type is equivalent to that of std::pow.

Example

int main()
{
// Uses specialisation for signed integers.
seqan3::debug_stream << seqan3::pow(2, 3u) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(-2, 3u) << '\n'; // Prints -8
// Uses specialisation for unsigned integers.
seqan3::debug_stream << seqan3::pow(2u, 3u) << '\n'; // Prints 8
// Uses `std::pow`.
seqan3::debug_stream << seqan3::pow(2, 3) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(2u, 3) << '\n'; // Prints 8
seqan3::debug_stream << seqan3::pow(2.0, 3) << '\n'; // Prints 8
// 5^25 should be 298023223876953125.
seqan3::debug_stream << seqan3::pow(5u, 25u) << '\n'; // Prints 298023223876953125
seqan3::debug_stream << static_cast<uint64_t>(std::pow(5u, 25u)) << '\n'; // Prints 298023223876953152 (wrong!)
}
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:37
base_t pow(base_t base, exp_t exp)
Computes the value of base raised to the power exp.
Definition: math.hpp:122
Provides math related functionality.
T pow(T... args)