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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:35:07+00:00 2026-06-03T09:35:07+00:00

As i understand, when you cast between 2 of these types with an arithmetic

  • 0

As i understand, when you cast between 2 of these types with an arithmetic operation in Java, for example double + int, the result will be as the bigger type (meaning in this example, the result will be double). What happens when you make an arithmetic operation on 2 types with the same size? what will int + float and long + double give? since int and float are 4 bytes each, and long and double are 8 bytes.

  • 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-03T09:35:08+00:00Added an answer on June 3, 2026 at 9:35 am

    This is all specified by the binary numeric promotion rules in the JLS. From http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2:

    When an operator applies binary numeric promotion to a pair of
    operands, each of which must denote a value that is convertible to a
    numeric type, the following rules apply, in order:

    1. If any operand is of a reference type, it is subjected to unboxing
      conversion (§5.1.8).

    2. Widening primitive conversion (§5.1.2) is applied to convert either or
      both operands as specified by the following rules:

      • If either operand is of type double, the other is converted to double.

      • Otherwise, if either operand is of type float, the other is converted
        to float.

      • Otherwise, if either operand is of type long, the other is converted
        to long.

      • Otherwise, both operands are converted to type int.

    After the type conversion, if any, value set conversion (§5.1.13) is
    applied to each operand.

    Binary numeric promotion is performed on the operands of certain operators:

    • The multiplicative operators *, / and % (§15.17)

    • The addition and subtraction operators for numeric types + and –
      (§15.18.2)

    • The numerical comparison operators <, <=, >, and >= (§15.20.1)

    • The numerical equality operators == and != (§15.21.1)

    • The integer bitwise operators &, ^, and | (§15.22.1)

    • In certain cases, the conditional operator ? : (§15.25)

    (“value set conversion” is about mapping between floating-point representations.)

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

Sidebar

Related Questions

I understand that if I cast it to a named type I can do
What is the difference between these two ways of casting in Java? (CastingClass) objectToCast;
I don't understand why I need to cast member variables to the proper type
Possible Duplicates: Why does null need an explicit type cast here? Nullable types and
I understand the difference between unsigned char * and char * types. I also
What is the actual difference between a long and an int in C#? I
I do not understand why the compiler can not see that a cast is
I was hoping for some help to understand why I need to re-cast my
As some of my code required implicit conversion between matrices of different types (e.g.
I thought that the correct type to use to store the difference between pointers

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.