value-preserving-literals 0.0.1
value-preserving literals for C++
Loading...
Searching...
No Matches
vir::constreal Struct Reference

Untyped real literal type. More...

#include <val.h>

Public Member Functions

template<__arithmetic _Up>
consteval operator _Up () const
 Conversion operator to arithmetic types.

Friends

consteval constreal operator- (constreal __v) noexcept
 Unary negation operator.
consteval constreal operator+ (constreal __v) noexcept
 Unary plus operator (identity)
consteval constreal operator~ (constreal)=delete
 Bitwise complement operator (deleted)
consteval constreal operator! (constreal)=delete("explicitly write 1 or 0 instead")
 Logical NOT operator (deleted)

Detailed Description

Untyped real literal type.

Represents a real value with up to the precision of long double.

Conversions to arithmetic types are only allowed when they are value-preserving. Otherwise, bad_value_preserving_cast is thrown.

Member Function Documentation

◆ operator _Up()

template<__arithmetic _Up>
vir::constreal::operator _Up ( ) const
inlineconsteval

Conversion operator to arithmetic types.

Converts to the target type only if the conversion is value-preserving. Checks that the value fits within the target range and can be exactly represented without precision loss.

Template Parameters
_UpTarget arithmetic type
Returns
_Up Converted value
Exceptions
bad_value_preserving_castif conversion is not value-preserving

◆ operator-

constreal operator- ( constreal __v)
friend

Unary negation operator.

Note
C++ only knows about positive literals. Subsequent unary minus produces a negative value.

◆ operator+

constreal operator+ ( constreal __v)
friend

Unary plus operator (identity)

Note
Provided for completeness. (Useless.)

◆ operator~

constreal operator~ ( constreal )
friend

Bitwise complement operator (deleted)

Not applicable to floating-point types.

◆ operator!

constreal operator! ( constreal )
friend

Logical NOT operator (deleted)

Explicitly write 1 or 0 instead.


The documentation for this struct was generated from the following file: