fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
Loading...
Searching...
No Matches
fp128::Double Struct Reference

Bit level view of an IEEE 754 double-precision value. More...

#include <fp128_shared.h>

Public Member Functions

constexpr Double (double v=0) noexcept
 Constructs from a double, or from positive zero when no value is given.
constexpr uint64_t f () const noexcept
 Mantissa (fraction) bits.
constexpr uint64_t e () const noexcept
 Biased exponent bits.
constexpr uint64_t s () const noexcept
 Sign bit (0 = positive, 1 = negative).
constexpr double val () const noexcept
 The double these bits encode.
constexpr void set_f (uint64_t v) noexcept
 Sets the mantissa. Bits above the field width are dropped, as a bit-field assignment would.
constexpr void set_e (uint64_t v) noexcept
 Sets the biased exponent. Bits above the field width are dropped.
constexpr void set_s (uint64_t v) noexcept
 Sets the sign bit.

Static Public Member Functions

static constexpr double make (uint64_t s, uint64_t e, uint64_t f) noexcept
 Assembles a double out of its three fields.

Public Attributes

uint64_t bits
 The raw bit pattern of the double.

Detailed Description

Bit level view of an IEEE 754 double-precision value.

Gives access to the mantissa, exponent and sign of a double without manual bit shifting, and assembles a double back out of those three fields.

The value is held as a raw bit pattern and converted with std::bit_cast rather than being overlaid with a union. The two produce identical code - a single move between register classes - but reading the inactive member of a union is not allowed during constant evaluation, which would keep every conversion between these types and a double out of a constant expression.

Definition at line 869 of file fp128_shared.h.

Constructor & Destructor Documentation

◆ Double()

fp128::Double::Double ( double v = 0)
inlineconstexprnoexcept

Constructs from a double, or from positive zero when no value is given.

Definition at line 873 of file fp128_shared.h.

Member Function Documentation

◆ f()

uint64_t fp128::Double::f ( ) const
inlinenodiscardconstexprnoexcept

Mantissa (fraction) bits.

Definition at line 876 of file fp128_shared.h.

◆ e()

uint64_t fp128::Double::e ( ) const
inlinenodiscardconstexprnoexcept

Biased exponent bits.

Definition at line 878 of file fp128_shared.h.

◆ s()

uint64_t fp128::Double::s ( ) const
inlinenodiscardconstexprnoexcept

Sign bit (0 = positive, 1 = negative).

Definition at line 880 of file fp128_shared.h.

◆ val()

double fp128::Double::val ( ) const
inlinenodiscardconstexprnoexcept

The double these bits encode.

Definition at line 882 of file fp128_shared.h.

◆ set_f()

void fp128::Double::set_f ( uint64_t v)
inlineconstexprnoexcept

Sets the mantissa. Bits above the field width are dropped, as a bit-field assignment would.

Definition at line 885 of file fp128_shared.h.

◆ set_e()

void fp128::Double::set_e ( uint64_t v)
inlineconstexprnoexcept

Sets the biased exponent. Bits above the field width are dropped.

Definition at line 887 of file fp128_shared.h.

◆ set_s()

void fp128::Double::set_s ( uint64_t v)
inlineconstexprnoexcept

Sets the sign bit.

Definition at line 889 of file fp128_shared.h.

◆ make()

constexpr double fp128::Double::make ( uint64_t s,
uint64_t e,
uint64_t f )
inlinestaticnodiscardconstexprnoexcept

Assembles a double out of its three fields.

Preferred over three set_ calls wherever the value is built from scratch: those each mask the old field out before merging the new one, which is wasted work when there is nothing there yet.

Parameters
sSign bit.
eBiased exponent. Bits above the field width are dropped.
fMantissa. Bits above the field width are dropped.
Returns
The assembled double.

Definition at line 903 of file fp128_shared.h.

Member Data Documentation

◆ bits

uint64_t fp128::Double::bits

The raw bit pattern of the double.

Definition at line 870 of file fp128_shared.h.


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