E.V.E  0.1-beta

◆ significants

eve::significants = {}
inlineconstexpr

Callable object computing the significants operation.

Required header: #include <eve/function/significants.hpp>

Members Functions

Member Effect
operator() the significants operation
operator[] Construct a conditional version of current function object

auto operator()( floating_real_value x, integral_real_value n ) const noexcept;
Definition: value.hpp:103
Definition: value.hpp:113

Parameters

x: floating real value.

n: integral real value.

Return value

Computes elementwise the rounding to n significants digits of x. With null n the result is a nan.

Warning
Floating numbers are not stored in decimal form. So if you try significants with a not exactly representable number the result can be not exactly what you expect.

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::significants

Parameters

cond : conditional expression

Return value

A Callable object so that the expression significants[cond](x, ...) is equivalent to if_else(cond,significants(x, ...),x)


Supported decorators

no decorators are supported

Example

See it live on Compiler Explorer

#include <eve/function/significants.hpp>
#include <eve/wide.hpp>
#include <eve/constant/mindenormal.hpp>
#include <eve/constant/minf.hpp>
#include <eve/constant/inf.hpp>
#include <eve/constant/nan.hpp>
#include <iostream>
#include <iomanip>
using iT = std::int32_t;
using wide_it = eve::wide<iT, eve::fixed<4>>;
int main()
{
wide_it qi = {0, 1, 2, 4};
wide_ft pf = {1.2345678901f, 1.2345678901f, 1.2345678901f, 1.2345678901f};
std::cout << "---- simd" << std::setprecision(8) << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qi = " << qi << '\n'
<< "-> significants(pf, qi) = " << eve::significants(pf, qi) << '\n';
float xf = 2.34316;
iT yi = 3;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yi = " << yi << '\n'
<< "-> significants(xf, yi) = " << eve::significants(xf, yi) << '\n';
return 0;
}
constexpr callable_significants_ significants
Callable object computing the significants operation.
Definition: significants.hpp:78
Wrapper for SIMD registers.
Definition: wide.hpp:65