What is the best technique for checking whether a floating point or double value is the same as exactly zero?

What will be an ideal response?


Due to the way floating point and double values are stored, it is not possible to perform accurate checking with the same as operator. The best technique to use for checking whether a floating point value is the same as zero (or any other value) is to obtain the absolute value of the difference of the number and what we are checking for, such as zero. If the difference is very small, such as 0.00001, we may assume the value is zero (or very close). For example, to check if the value of the variable “x” is zero, the check could be performed as shown here:
double x;
// set the value in x
if( fabs(x – 0.0) < 0.00001) // checking to see if x is 0.0
{
// assume x is 0.0
}

double y;
// set the value in y
if( fabs(y – 25.0) < 0.00001) // checking to see if y is 25.0
{
// assume y is 25.0
}

Computer Science & Information Technology

You might also like to view...

Scenario #2 ABC is a mid-size animation company that has historically worked on some of the major animation movies in the last few years. Their core competence is their animation engineers, and their very talented IT staff that manages their server farms and develops new versions of their custom animation software. When they are working on a particular animation sequence, their typical development cycle involves large spikes in computing and storage usage, as they render each section and each version. Over the years, as animations have become more sophisticated, these spikes have become larger and more unpredictable as they start pushing the boundaries of what is computationally possible. Consequently, they have seen their hardware and IT costs increase at a rapid rate in order to service

IaaS PaaS SaaS

Computer Science & Information Technology

All the following are reasons to collaborate online EXCEPT for:

A) a team of IT professionals living in different countries collaborating on a big project. B) several friends working on their tax returns. C) a bunch of college students working on a group project. D) small business owners presenting their products or services to potential clients.

Computer Science & Information Technology

Any file you open that was downloaded from the Internet, accessed from a shared network, or received as an e-mail attachment may open in a read-only format, called ____ View.

A. Secure B. Scanned C. Quarantine D. Protected

Computer Science & Information Technology

You want a clip to appear full-screen for a few seconds and then spin away. How do you make the animation of the Rotation setting start part way through a clip rather than at the beginning?

What will be an ideal response?

Computer Science & Information Technology