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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:27:56+00:00 2026-06-11T08:27:56+00:00

Below I attempt to assign to value the maximum Long value, then add to

  • 0

Below I attempt to assign to value the maximum Long value, then add to it the minimum positive Double value possible.

I then try to detect that the value is greater than the maximum Long value.

Double value = new Long(Long.MAX_VALUE).doubleValue();
value += Double.MIN_VALUE;
if (value < -(new Long(Long.MAX_VALUE).doubleValue()) || value > new Long(Long.MAX_VALUE).doubleValue()) {
  // Expecting code here to execute, but it doesn't.
}

Studying the values involved shows that value has the final value of

9.223372036854776E18
= 9223372036854776000

while Long.MAX_VALUE has the value

9223372036854775807

Comparing these shows that value is greater as expected:

9223372036854776000 (value)
9223372036854775807 (Long.MAX_VALUE)

Could someone please explain why the if statement fails to detect this?

Sincere thanks.

  • 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-11T08:27:57+00:00Added an answer on June 11, 2026 at 8:27 am

    Long.MAX_VALUE can’t be represented exactly as a double. The closest available double value is 9223372036854775808.

    Adding Double.MIN_VALUE to that number (10^-1074) does not change anything because the closest double value to 9223372036854775808 + 10^-1074 still is 9223372036854775808.

    Using @PeterLawrey’s code, you can see that the next available double is 9223372036854777856 (which is equal to Long.MAX_VALUE + 2048).

    Note: your double is actually equal to 9223372036854775808, which gets printed as 9.223372036854776E18. You can see it with the following code:

    double d = Long.MAX_VALUE;
    BigDecimal bd= new BigDecimal(d);
    System.out.println(bd);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would i add key commands to the sprite plumbers? Below is my attempt
When I attempt to run the script below in Eclipse(PyDev): import subprocess subprocess.call(/usr/local/bin/mitmdump) An
Below is the code I am using and the error happens when I attempt
The routine below inserts a page, sets permalinks to postname then attempts to update
Below is code to an inherited ComboBox. The issue is that the ComboBox is
Is it possible to swap a reference of an object that an array element
I have created a little example(below) on my attempt to safely stop multiple threads
Below is my attempt to iterate a sequence of maps; the code fails due
I am trying to dynamically allocate an array of base(Student) classes, and then assign
I am using this slice of code (shown below) in an attempt to populate

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.