xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::numeric Namespace Reference

Numeric utilities. More...

Classes

struct  IeeeFloatingPointTraits
 Information about an IEEE floating point type. More...
 

Functions

template<std::integral Target, std::integral Source>
constexpr auto clamp (Source source) -> Target
 Converts an integer to a new type using clamping.
 
template<tools::Arithmetic Type>
constexpr auto maxStringSize () -> std::size_t
 Returns the maximum length needed to hold a number of a certain type.
 
template<typename Char , typename Number , typename CharTraits = std::char_traits<Char>>
auto toBasicString (Number number) -> string::BasicStaticString< Char, maxStringSize< Number >(), CharTraits >
 Converts a number to a string.
 
template<tools::Arithmetic Number>
auto toString (Number number) -> string::StaticString< maxStringSize< Number >()>
 Converts a number to a string of type char
 
template<tools::Arithmetic Number>
auto toWString (Number number) -> string::StaticWString< maxStringSize< Number >()>
 Converts a number to a string of type wchar_t
 
template<tools::Arithmetic Number>
auto toU8String (Number number) -> string::StaticU8String< maxStringSize< Number >()>
 Converts a number to a string of type char8_t
 
template<tools::Arithmetic Number>
auto toU16String (Number number) -> string::StaticU16String< maxStringSize< Number >()>
 Converts a number to a string of type char16_t
 
template<tools::Arithmetic Number>
auto toU32String (Number number) -> string::StaticU32String< maxStringSize< Number >()>
 Converts a number to a string of type char32_t
 

Detailed Description

Numeric utilities.

This namespace contains numeric utilities.

Function Documentation

◆ clamp()

template<std::integral Target, std::integral Source>
constexpr auto xentara::utils::numeric::clamp ( Source  source) -> Target
constexpr

Converts an integer to a new type using clamping.

Converts an integer to a new type. If the value lies outside the range of the new type, the closest possible value is returned.

Include file
#include <xentara/utils/numeric/clamp.hpp>
Parameters
sourceThe source integer
Returns
The closest possible target integer

◆ maxStringSize()

template<tools::Arithmetic Type>
constexpr auto xentara::utils::numeric::maxStringSize ( ) -> std::size_t
constexpr

Returns the maximum length needed to hold a number of a certain type.

This function can be used to preallocate buffers used to format numeric strings.

Include file
#include <xentara/utils/numeric/maxStringSize.hpp>
Returns
The maximum buffer size required to format the number, using the format used by std::to_chars.

◆ toBasicString()

template<typename Char , typename Number , typename CharTraits = std::char_traits<Char>>
auto xentara::utils::numeric::toBasicString ( Number  number) -> string::BasicStaticString<Char, maxStringSize<Number>(), CharTraits>

Converts a number to a string.

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number

◆ toString()

template<tools::Arithmetic Number>
auto xentara::utils::numeric::toString ( Number  number) -> string::StaticString<maxStringSize<Number>()>

Converts a number to a string of type char

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number

◆ toU16String()

template<tools::Arithmetic Number>
auto xentara::utils::numeric::toU16String ( Number  number) -> string::StaticU16String<maxStringSize<Number>()>

Converts a number to a string of type char16_t

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number

◆ toU32String()

template<tools::Arithmetic Number>
auto xentara::utils::numeric::toU32String ( Number  number) -> string::StaticU32String<maxStringSize<Number>()>

Converts a number to a string of type char32_t

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number

◆ toU8String()

template<tools::Arithmetic Number>
auto xentara::utils::numeric::toU8String ( Number  number) -> string::StaticU8String<maxStringSize<Number>()>

Converts a number to a string of type char8_t

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number

◆ toWString()

template<tools::Arithmetic Number>
auto xentara::utils::numeric::toWString ( Number  number) -> string::StaticWString<maxStringSize<Number>()>

Converts a number to a string of type wchar_t

Include file
#include <xentara/utils/numeric/toString.hpp>
Parameters
numberThe number
Returns
A string containing the number