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

  • Home
  • SEARCH
  • 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 7308183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:31:21+00:00 2026-05-28T23:31:21+00:00

It makes sense to define mathematical constants as double values but what happens when

  • 0

It makes sense to define mathematical constants as double values but what happens when one requires float values instead of doubles? Does the compiler automatically interpret the doubles as floats at compile-time (so they are actually treated as they were const floats) or is this conversion made at runtime?

  • 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-28T23:31:21+00:00Added an answer on May 28, 2026 at 11:31 pm

    If by “defining”, you mean using #define, here’s what happens:

    Say you have:

    #define CONST1 1.5
    #define CONST2 1.12312455431461363145134614  // Assume some number too
                                                 // precise for float
    

    Now if you have:

    float x = CONST1;
    float y = CONST2;
    

    you don’t get any warning for x because the compiler automatically makes CONST1 a float. For y, you get a warning because CONST2 doesn’t fit in a float, but the compiler casts it to float anyway.


    If by “defining”, you mean using const variables, here’s what happens:

    Say you have

    const double CONST1=1.5;
    const double CONST2=1.12312455431461363145134614; // Assume some number too
                                                      // precise for float
    

    Now if you have:

    float x = CONST1;
    float y = CONST2;
    

    there is no way for the compiler to know the values of CONST1 and CONST2(*) and therefore cannot interpret the values as float at compile them. You will be given two warnings about possible loss of data and the conversion will be done at runtime.

    (*) Actually there is a way. Since the values are const, the optimizer may decide not to take a variable for them, but replace the values throughout the code. This could get complicated though, as you may pass the address to these variables around, so the optimizer may decide not to do that. That is, don’t count on it.


    Note that, this whole thing is true for any basic type conversions. If you have

    #define CONST3 1
    

    then you think CONST3 is int, but if you put it in a float, it would become float at compile-time, or if you put it in a char, it would become char at compiler-time.

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

Sidebar

Related Questions

Does it makes sense that when columns of a datagridview are cleared, all rows
Imagine I've got a data object that makes sense in an OO model, but
Ahh, C++ templates... The code I see, makes sense to me, but GCC... it
It makes sense that something like an operating system would be written in C.
It makes sense to pass a filter object to the repository so it can
I hope the title makes sense. I have a set of items that I
It now makes sense that the versions aren't right. I know I am using
Hope this makes sense... Is there a simple way to return a set of
While the NSCurrentLocaleDidChangeNotification perfectly makes sense on Mac OS X, I don't see how
Is it possible or makes sense to have static dynamic variables on a class,

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.