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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:07:48+00:00 2026-06-02T23:07:48+00:00

First, this isn’t a question about precision or anything like that. My question is,

  • 0

First, this isn’t a question about precision or anything like that.

My question is, how does the compiler decide how to represent a number?

Let’s take C for example. I write

double d = 4.5632;

How does it pick its binary representation? I know it’s not represented exactly, so how does it choose the closest representable number? Is it done at compile time? Is it done by the CPU or the OS?

Please only answer if you know how this happens, answers like “don’t worry about it” are not helpful. Also, “it depends on the platform” isn’t helpful also, you can pick a platform and explain for that.

  • 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-02T23:07:50+00:00Added an answer on June 2, 2026 at 11:07 pm

    The compiler doesn’t decide (typically). The CPU (typically) has a floating-point unit, which requires floating-point values to be represented in a particular format (it’s typically IEEE-754). Of course, it’s possible to emulate an entirely different architecture, in which case the compiler/emulator author is free to pick an entirely different representation. But this isn’t typical.

    As to how the specific lexical representation 4.5632 is converted to the underlying representation, that’s specified by the C standard. So from section 6.4.4.2 of the C99 standard (I’ve highlighted the most relevant part):

    The significand part is interpreted as a (decimal or hexadecimal)
    rational number; the digit sequence in the exponent part is
    interpreted as a decimal integer. For decimal floating constants, the
    exponent indicates the power of 10 by which the significand part is to
    be scaled. For hexadecimal floating constants, the exponent indicates
    the power of 2 by which the significand part is to be scaled. For
    decimal floating constants, and also for hexadecimal floating
    constants when FLT_RADIX is not a power of 2, the result is either the
    nearest representable value, or the larger or smaller representable
    value immediately adjacent to the nearest representable value, chosen
    in an implementation-defined manner
    . For hexadecimal floating
    constants when FLT_RADIX is a power of 2, the result is correctly
    rounded.

    This will be done at compile-time (although the standard doesn’t mandate that).

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

Sidebar

Related Questions

First of all, this isn't another question about storing images on DB vs file
First this question isn't about trying to solve a specific problem. As newcomer to
I know that this isn't the first time that this question has been asked,
First of all, sorry if this isn't an appropriate question for StackOverflow. I've tried
first of all this is my third question about web services here and i
First off: I know that this isn't reliable for actually checking if I can
Ok... First off, I know this isn't a new question. But, for some reason
This isn't a question that has a black/white yes/no answer, this is more a
First, I want to point out that this isn't really x86, it's msx88 which
This isn't quite the same question as many others that it might resemble. Consider

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.