/*******************************************************************************
*                                                                              *
*  File:        IntegerDomain.java                      Revision:  1.0         *
*                                                                              *
*  Contents:    determines the range of integer values a Java double value is  *
*               able to reprsent exactly(!)                                    *
*                                                                              *
*  Creation:    14.11.2004                     Last Modification:  14.11.2004  *
*                                                                              *
*  Platform:    IBM-compatible PC running Windows 98SE                         *
*                                                                              *
*  Environment: Java 1.4                                                       *
*                                                                              *
*  Author:      Andreas Rozek           Phone:  ++49 (7031) 222305             *
*               Bunsenstraße 80/1       Fax:    -                              *
*             D-71032 Böblingen         EMail:  Info@Andreas-Rozek.De          *
*               Germany                                                        *
*                                                                              *
*  URL:         http://www.Andreas-Rozek.de/                                   *
*                                                                              *
*  Copyright:   this software is published under the  "GNU Lesser General Pub- *
*               lic  License"  (see  "http://www.fsf.org/copyleft/lesser.html" *
*               for additional information)                                    *
*                                                                              *
*  Comments:    (none)                                                         *
*                                                                              *
*******************************************************************************/

public class IntegerDomain {
  public static void main (String[] ArgList) {
    System.out.println();
    System.out.println("IntegerDomain - what is the largest integer represented by a double?");
    System.out.println();

    long Step = 2;
    for (;;) {
      long   nextStep  = Step*2;
      double Candidate = (double) nextStep;
      if ((Math.round(Candidate) == nextStep) && (Candidate+1 != Candidate)) {
        Step = nextStep;
      } else {
        break;
      };
    };

    long Limit = Step; Step = Step/2;
    while (Step > 0) {
      long   nextLimit = Limit+Step;
      double Candidate = (double) nextLimit;
      if ((Math.round(Candidate) == nextLimit) && (Candidate+1 != Candidate)) {
        Limit = nextLimit;
      };

      Step = Step/2;
    };

    System.out.println("supported integer range is: -" + Limit + "...+" + Limit);
  };
};

