E.V.E
v2022.09.01

◆ significants

eve::significants = {}
inlineconstexpr

Computes the rounding to n significants digits of the first input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T, eve::integral_value N >
eve::common_compatible_t<T, N> significants(T x, N n) noexcept;
}
constexpr callable_significants_ significants
Computes the rounding to n significants digits of the first input.
Definition: significants.hpp:55
Definition: all_of.hpp:22

Parameters

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.

Example

#include <eve/module/math.hpp>
#include <eve/wide.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;
}
Wrapper for SIMD registers.
Definition: wide.hpp:65