Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:43:19+00:00 2026-05-26T18:43:19+00:00

On the Windows XP..7 platforms, for x86 instruction sets, using standard C++ or a

  • 0

On the Windows XP..7 platforms, for x86 instruction sets, using standard C++ or a Microsoft compiler, is there a value I can assign a double which, when other computations are applied to it, will always result in that same value?

e.g.

const double kMagicValue = ???;
double x = kMagicValue;
cout << x * 9.1; // still outputs kMagicValue

As I understand it, there is a floating point error condition that once trigged, the remainder of all floating point computations will result in NAN or something similar…

I ask because I have a series of functions that try to compute a double for a given input, and for some inputs, “no answer (NAN)” is a good output (conceptually).

And I want to be able to be lazy, and string together computations that should, if any part results in NAN, result as a whole in NAN (i.e. kMagicValue).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:43:20+00:00Added an answer on May 26, 2026 at 6:43 pm

    You shouldn’t rely on NaN to do the job. It will always compare false to any value, including itself, and you have to make sure that the platform respects IEEE754 semantics to a certain extent (this includes having a NaN in the first place).

    See horror stories there: Negative NaN is not a NaN?

    If you really want this approach, and you are confident enough about IEEE754 support, be sure to compile with /fp:precise (since you use MSVC) so that the compiler doesn’t optimize away stuff like 0 * NaN. Be aware that this might impact performance.

    To get a NaN,

    std::numeric_limits<double>::quiet_NaN()
    

    To test for NaN

    inline bool is_NaN(double x) { return !(x == x); }
    

    But this approach is probably more trouble than it is worth. I’d rather use exceptions for control flow here.

    The right thing to use is boost::optional<double>, but it can be a little verbose at some places

    [Also, the Haskell language has first-class support for these kind of control flow, if C++ is not a must-go option, Maybe you can give it a try.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Turbo C compiler on a Windows platform, Intel x86 architecture.
I'm interested in using F# for numerical work, but my platforms are not windows
Using unmanaged C++ on a Windows platform, is there a simple way to detect
I have a need to work with Windows executables which are made for x86,
We have a Perl program that ran well on all Windows platforms so far.
What's the best way to maintain a multiple databases across several platforms (Windows, Linux,
Would this work on all platforms? i know windows does \r\n, and remember hearing
I write applications for various platforms, but chiefly OS X and Windows. On both,
I'm developing on 32bit windows and am using appassembler to create a java service
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(2341,9): error MSB3171: Problem generating manifest. Could not load file or assembly '...CppCli.dll.manifest' or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.