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 7575033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:35:05+00:00 2026-05-30T16:35:05+00:00

Compilers are allowed to make several assumptions that would lead to undefined behaviour (such

  • 0

Compilers are allowed to make several assumptions that would lead to undefined behaviour (such as assuming addition doesn’t overflow). May they make such an assumption with regards to floating point NaN?

For example:

double a = some_calc();
double b = a;
if( a == b )
  do_something();

Can the optimizer remove the conditional statement and assume that it is always true? Or is it bound to the platform floating point rules (IEEE) and forced to do the check in case the value is NaN?

That is, can the compiler optimize based on the assumption that a double does not contain NaN? As the C++ standard doesn’t say a lot about how floating point actually works on the platform, I’m not clear if this is actually fully specified.

  • 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-30T16:35:07+00:00Added an answer on May 30, 2026 at 4:35 pm

    Or is it bound to the platform floating point rules (IEEE)

    Not necessarily, if the implementation uses IEEE 754 floating point numbers, std::numeric_limits<double>::is_iec559 is set to true.

    and forced to do the check in case the value is NaN?

    If the implementation does use IEEE 754, the result of arithmetic operations must match IEEE floating point rules, but as far as comparison goes, it can be optimised. If the body of some_calc is available for the analysis by the compiler in the same translation unit (or during link-time code generation) and it can conclude that it never returns NaN (i.e. returns a constant), it can be optimised, as the semantics of the code don’t change.

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

Sidebar

Related Questions

Are there compilers for high-level languages (such as C) which can be targeted to
I always wonder why compilers can't figure out simple things that are obvious to
Any existing Flash SWF compilers that can understand directives like #IF #ENDIF , etc?
Do you know of any compilers that only requires one or two clicks on
Question: How do i make xjc/Jaxb generate the propper javaclasses for several schemas containing
Possible Duplicate: Why doesn't GCC optimize structs? Why doesn't C++ make the structure tighter?
I'm trying to make a compiler for my game (so that people could do
I would like to define a type such as: type blah = AThing |
Maybe I am not from this planet, but it would seem to me that
Upcasting is allowed in Java, however downcasting gives a compile error. The compile error

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.