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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:08:13+00:00 2026-06-14T21:08:13+00:00

Consider the following java code: String toParse = 1.7976931348623157E308; //max value of a double

  • 0

Consider the following java code:

String toParse = "1.7976931348623157E308"; //max value of a double in java        
double parsed = Double.parseDouble(toParse);
System.out.println(parsed);

For the mentioned value of 1.7976931348623157E308 everything makes sense and one gets the correct output.

Now, if one tries to parse 1.7976931348623158E308 (last digit before E incremented) you still get the maximum value printed into the console!
Only after trying to parse 1.7976931348623159E308 (again the last digit got incremented) and greater one gets Infinity.
Same behaviour for the corresponding negative values.

Why is ... 8E308 parsed to ... 7E308 and not Infinity?

  • 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-14T21:08:14+00:00Added an answer on June 14, 2026 at 9:08 pm

    The SE 7 version of the parseDouble documentation refers to the valueOf documentation which says:

    Note that the round-to-nearest rule also implies overflow and underflow behaviour; if the exact value of s is large enough in magnitude (greater than or equal to (MAX_VALUE + ulp(MAX_VALUE)/2), rounding to double will result in an infinity and if the exact value of s is small enough in magnitude (less than or equal to MIN_VALUE/2), rounding to float will result in a zero.

    This is consistent with the statement that the rounding to type double is by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic.

    You have to imagine the conversion being done by first calculating the nearest floating point number ignoring the exponent limitation, and then checking whether the exponent fits. Double.MAX_VALUE is the closest number under that rule to some numbers that are strictly greater than it.

    To confirm this is normal rounding behavior, consider the following program:

        public class Test {
          public static void main(String[] args) {
            double ulp = Math.ulp(Double.MAX_VALUE);
            System.out.println(ulp);
            System.out.println(Double.MAX_VALUE);
            System.out.println(Double.MAX_VALUE+ulp/2.0000000001);
            System.out.println(Double.MAX_VALUE+ulp/2);
          }
        }
    

    It outputs:

    1.9958403095347198E292
    1.7976931348623157E308
    1.7976931348623157E308
    Infinity
    

    Adding something even slightly less than half a ulp to Double.MAX_VALUE does not change it. Adding half a ulp overflows to infinity.

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

Sidebar

Related Questions

Consider the following Java code: String str = \u8ba9\u4ed6\u51fa\u6d77\u4e86; // ... System.out.print(str); I want
Consider the following classes in Java class A { protected void methodA() { System.out.println(methodA()
Consider the following example. String str = new String(); str = "Hello"; System.out.println(str); //Prints
Consider the following code: java.util.Map<String, String> map = new java.util.HashMap<String, String>(); ... String key
Consider the following Java code: public class Test { private Foo< String, String >
Consider the following Java code: volatile boolean v1 = false; volatile boolean v2 =
Java noob question: Consider the following C array and initializer code: struct { int
I have a question about how GC works in Java. Consider the following code:
Consider the following code: class Foo(var name: String = bar) Now i try to
Consider the following code public class sqldetails extends JFrame implements ActionListener{ static String username=null;

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.