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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:52:07+00:00 2026-06-18T07:52:07+00:00

Considering this code snippet: int i = 0; double d1 = (double) i; long

  • 0

Considering this code snippet:

int i = 0;
double d1 = (double) i;
long l = 0L;
double d2 = (double) l;

Running this on my machine prints 0.0 for both conversions. But can d1 and d2 ever be anything but 0.0?

As I understand, this is a widening primitive conversion to which the spec says:

A widening primitive conversion does not lose information about the
overall magnitude of a numeric value.

as well as

A widening conversion of an int or a long value to float, or of a long
value to double, may result in loss of precision

As I understand the spec, the above would mean that int 0 will always become double 0.0 but long 0 can be converted to something else (e.g. 1E-20 or something like that). Is my spec interpretation correct?

  • 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-18T07:52:09+00:00Added an answer on June 18, 2026 at 7:52 am

    The full quote is:

    A widening conversion of an int or a long value to float, or of a long value to double, may result in loss of precision – that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using IEEE 754 round-to-nearest mode.

    (Emphasis mine)

    This is covering the case where the int/long value cannot be exactly represented in float/double (in which case, the nearest representable value is chosen). Clearly, 0 can be represented, so one would not expect a loss of precision.

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

Sidebar

Related Questions

Considering this code with 3 differents function call semantics: void f(void){ puts(OK); } int
I have this snippet of code which I am considering to simplfy: if (numberOfResults
This is the snippet of code in Java language: public void name(){ int value
Considering this code, VC9 doesn't detect aliasing : typedef struct { int x, y;
considering this code i put a bp at the end of roll(int n) and
Considering this code, can I be absolutely sure that the finally block always executes,
Considering this basic code snippet: <? class mcClassington { var $mcProperty='default'; function mcDoSomething() {
Considering this code: std::vector<myObject*> veryLargeArray; for (int i = 0; i < veryLargeArray.size(); ++i)
Considering this article Developing a MVC component for Joomla , following is the code
I apologize if this code looks a bit like a mess (considering the length);

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.