Skip to content

Number test context precision error, decimal place rounding and bool cast functors and tests - #11

Open
abstrackt wants to merge 5 commits into
mis-wut:masterfrom
gprabowski:gpu_project_2023_dev
Open

abstrackt wants to merge 5 commits into
mis-wut:masterfrom
gprabowski:gpu_project_2023_dev

Conversation

@abstrackt

@abstrackt abstrackt commented May 18, 2023

Copy link
Copy Markdown

Number test context contained invalid values for the m_max_precision variable. This limited test data to three digits, meaning for example that any floating point numbers above 10 would get truncated to 10.x, instead of 10.xxx, etc. This created issues with some tests which deal with truncating numbers.

Also added simple rounding and bool cast functors with tests as described below.

@abstrackt abstrackt changed the title Number test context precision error Number test context precision error, decimal place rounding and bool cast functors and tests May 18, 2023
template <class NumberT> inline __device__ Num operator()(NumberT c) const {
Num val = static_cast<Num>(c);
Num div = static_cast<Num>(pow(10.0, Dec));
val = trunc(val*div)/div;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiply by a power of 10, truncate to the nearest integer to cut the remaining decimal places and divide to revert to the original value.

constexpr static In Zero = static_cast<In>(0);

template <class NumberT> inline __device__ bool operator()(NumberT c) const {
In val = static_cast<In>(c);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple cast depending on the sign of the input value

@gprabowski

Copy link
Copy Markdown

this fixes issue #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants