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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:29:20+00:00 2026-06-18T10:29:20+00:00

This method returns ‘true’. Why ? public static boolean f() { double val =

  • 0

This method returns ‘true’. Why ?

public static boolean f() {
   double val = Double.MAX_VALUE/10;
   double save = val;
   for (int i = 1; i < 1000; i++) {
       val -= i;
   }
   return (val == save);
}
  • 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-18T10:29:21+00:00Added an answer on June 18, 2026 at 10:29 am

    You’re subtracting quite a small value (less than 1000) from a huge value. The small value is so much smaller than the large value that the closest representable value to the theoretical result is still the original value.

    Basically it’s a result of the way floating point numbers work.

    Imagine we had some decimal floating point type (just for simplicity) which only stored 5 significant digits in the mantissa, and an exponent in the range 0 to 1000.

    Your example is like writing 10999 – 1000… think about what the result of that would be, when rounded to 5 significant digits. Yes, the exact result is 99999…..9000 (with 999 digits) but if you can only represent values with 5 significant digits, the closest result is 10999 again.

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

Sidebar

Related Questions

My static method returns the following concatenated string like this return (Sb.ToString() + +
Why in this example from MSDN, in GetEnumerator method, PeopleEnum returns IEnumerator ? public
Found this method in System class. Just curious to know about it- public static
Actually, I have this Method wich returns all fields of my table. public ActionResult
activityManager.getRunningServices(Integer.MAX_VALUE); This method returns a list which includes service which is stopped manually. Settings
I'm binding to a Service, using context.bindService(bindIntent, connection, Context.BIND_AUTO_CREATE); . This method returns true
I've tentatively written this method: public static Func<T> WeakCacheFor<T>( Func<T> provider ) where T:
Is there a way to say this method returns this using Generics? Of course,
How can i convert int64_t to NSInteger in Objective-C ? This method returns into
All, I have a method that returns a List. This method is used to

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.