ashkan
ashkan

Reputation: 166

CUDA Floating Point Compare

I was wondering if anybody has a good implementation of floating point/ double comparison for CUDA. I'd like to use something (semi) standard, instead of writing my own. I couldn't find something standard, or endorsed by CUDA. But here are some good resources on the topic:

http://developer.download.nvidia.com/assets/NVIDIA-CUDA-Floating-Point.pdf

http://www.mrupp.info/Data/2007floatingcomp.pdf

something with following header, optimized for running on CUDA // Usable AlmostEqual function bool fcmp(double a, double b)

cheers, Ashkan

Upvotes: 1

Views: 2411

Answers (1)

Nathan Whitehead
Nathan Whitehead

Reputation: 2012

There are several ways to compare floating point numbers. You can look at the absolute difference between the numbers. You can look at the relative difference between the numbers, taking the absolute difference divided by whichever number is the reference. You can look at bitwise equality of the floating point representations.

Without knowing why you're comparing two numbers it's hard to say which is best for you. There is no official CUDA-endorsed way to compare floating point numbers, other than the == operator which is defined by IEEE-754.

Upvotes: 5

Related Questions