Loading...
Searching...
No Matches
Utility

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

Collaboration diagram for Utility:

## Topics

| 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] | base | The base to compute the power for.
  [in] | exp | The power to raise base to.

Returns
  .

Exceptions

  std::overflow_error | if an overflow occurs (Only in Debug build).
  std::underflow_error | if 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

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/utility/math.hpp>
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!)
}
debug_stream.hpp
Provides seqan3::debug_stream and related types.
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
seqan3::pow
base_t pow(base_t base, exp_t exp)
Computes the value of base raised to the power exp.
Definition math.hpp:120
math.hpp
Provides math related functionality.
std::pow
T pow(T... args)
Hide me