NumericAL
A header-only C++20 lexer built on REAL
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
numerical::detail::decimal_rounding< R, C > Struct Template Reference

A real of type R rounded to decimals places, half to even, as numpy.round: nearbyint(x · 10ᵈ) / 10ᵈ (nearbyint(x / 10⁻ᵈ) · 10⁻ᵈ for a negative d), computed in C. More...

#include <tensor_ops.hpp>

Collaboration diagram for numerical::detail::decimal_rounding< R, C >:
[legend]

Public Member Functions

 decimal_rounding (int places) noexcept
 
R operator() (R x) const noexcept
 

Public Attributes

int decimals
 The places; fewer than none round to tens, hundreds and so on.
 
C scale
 10 to the magnitude of decimals, in C.
 
C exact_from
 The magnitude from which a value is its own rounding (decimals above 0).
 

Detailed Description

template<std::floating_point R, std::floating_point C>
struct numerical::detail::decimal_rounding< R, C >

A real of type R rounded to decimals places, half to even, as numpy.round: nearbyint(x · 10ᵈ) / 10ᵈ (nearbyint(x / 10⁻ᵈ) · 10⁻ᵈ for a negative d), computed in C.

An x of magnitude 2ᵖ · 10⁻ᵈ or more (p the digits of R's significand) has an ulp coarser than the places: its decimal rounding lies within half a place of it, nearer than any other value, so it is kept. Its product by 10ᵈ, which NumPy's computes, can round off its last bit or overflow (round(1e307, 2)); below, the product is under 2ᵖ. A finite x rounds to ±0 where 10⁻ᵈ overflows C.

Definition at line 2923 of file tensor_ops.hpp.

Constructor & Destructor Documentation

◆ decimal_rounding()

template<std::floating_point R, std::floating_point C>
numerical::detail::decimal_rounding< R, C >::decimal_rounding ( int  places)
inlineexplicitnoexcept

Definition at line 2928 of file tensor_ops.hpp.

Member Function Documentation

◆ operator()()

template<std::floating_point R, std::floating_point C>
R numerical::detail::decimal_rounding< R, C >::operator() ( R  x) const
inlinenoexcept

Definition at line 2934 of file tensor_ops.hpp.

Member Data Documentation

◆ decimals

template<std::floating_point R, std::floating_point C>
int numerical::detail::decimal_rounding< R, C >::decimals

The places; fewer than none round to tens, hundreds and so on.

Definition at line 2924 of file tensor_ops.hpp.

◆ exact_from

template<std::floating_point R, std::floating_point C>
C numerical::detail::decimal_rounding< R, C >::exact_from

The magnitude from which a value is its own rounding (decimals above 0).

Definition at line 2926 of file tensor_ops.hpp.

◆ scale

template<std::floating_point R, std::floating_point C>
C numerical::detail::decimal_rounding< R, C >::scale

10 to the magnitude of decimals, in C.

Definition at line 2925 of file tensor_ops.hpp.


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