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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:49:17+00:00 2026-06-18T12:49:17+00:00

Assuming IEEE-754 conformance, is a float guaranteed to be preserved when transported through a

  • 0

Assuming IEEE-754 conformance, is a float guaranteed to be preserved when transported through a double?

In other words, will the following assert always be satisfied?

int main()
{
    float f = some_random_float();
    assert(f == (float)(double)f);
}

Assume that f could acquire any of the special values defined by IEEE, such as NaN and Infinity.

According to IEEE, is there a case where the assert will be satisfied, but the exact bit-level representation is not preserved after the transportation through double?

The code snippet is valid in both C and C++.

  • 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-06-18T12:49:18+00:00Added an answer on June 18, 2026 at 12:49 pm

    You don’t even need to assume IEEE. C89 says in 3.1.2.5:

    The set of values of the type float is a subset of the set of values
    of the type double

    And every other C and C++ standard says equivalent things. As far as I know, NaNs and infinities are “values of the type float“, albeit values with some special-case rules when used as operands.

    The fact that the float -> double -> float conversion restores the original value of the float follows (in general) from the fact that numeric conversions all preserve the value if it’s representable in the destination type.

    Bit-level representations are a slightly different matter. Imagine that there’s a value of float that has two distinct bitwise representations. Then nothing in the C standard prevents the float -> double -> float conversion from switching one to the other. In IEEE that won’t happen for “actual values” unless there are padding bits, but I don’t know whether IEEE rules out a single NaN having distinct bitwise representations. NaNs don’t compare equal to themselves anyway, so there’s also no standard way to tell whether two NaNs are “the same NaN” or “different NaNs” other than maybe converting them to strings. The issue may be moot.

    One thing to watch out for is non-conforming modes of compilers, in which they keep super-precise values “under the covers”, for example intermediate results left in floating-point registers and reused without rounding. I don’t think that would cause your example code to fail, but as soon as you’re doing floating-point == it’s the kind of thing you start worrying about.

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

Sidebar

Related Questions

Assuming: std::string ToShow,NumStr; The following displays This is 19 ch00: ToShow = This is
assuming I have the following array: views = [ { :user_id => 1, :viewed_at
Assuming that the larger a database gets, the longer it will take to SELECT
assuming following: public class Enterprise { private int id; private String name; } public
Assuming that I have the following code: final Catalog catalog = createCatalog(); for (int
Assuming that we have the following table: Person: PersonID, Name, Age, Gender And we
Assuming I have the following html div which I want to replicate its children,
Assuming the following: /* drop index ix_vouchers_nacsz on dbo.vouchers; drop index ix_vouchers_nacsz2 on dbo.vouchers;
Assuming I have a JQuery object stored in $e obtained through this selector: var
Assuming I have the following list: IList<string> list = new List<string>(); list.Add(Mouse); list.Add(Dinner); list.Add(House);

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.