gt:         if (radix < Character.MIN_RADIX) {
context: /*
   * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the LICENSE file that accompanied this code.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  package java.lang;
  
  /**
   * The {@code Long} class wraps a value of the primitive type {@code
   * long} in an object. An object of type {@code Long} contains a
   * single field whose type is {@code long}.
   *
   * <p> In addition, this class provides several methods for converting
   * a {@code long} to a {@code String} and a {@code String} to a {@code
   * long}, as well as other constants and methods useful when dealing
   * with a {@code long}.
   *
   * <p>Implementation note: The implementations of the "bit twiddling"
   * methods (such as {@link #highestOneBit(long) highestOneBit} and
   * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
   * based on material from Henry S. Warren, Jr.'s <i>Hacker's
   * Delight</i>, (Addison Wesley, 2002).
   *
   * @author  Lee Boynton
   * @author  Arthur van Hoff
   * @author  Josh Bloch
   * @author  Joseph D. Darcy
   * @since   JDK1.0
   */
  public final class Long extends Number implements Comparable<Long> {
      /**
       * A constant holding the minimum value a {@code long} can
       * have, -2<sup>63</sup>.
       */
      public static final long MIN_VALUE = 0x8000000000000000L;
  
      /**
       * A constant holding the maximum value a {@code long} can
       * have, 2<sup>63</sup>-1.
       */
      public static final long MAX_VALUE = 0x7fffffffffffffffL;
  
      /**
       * The {@code Class} instance representing the primitive type
       * {@code long}.
       *
       * @since   JDK1.1
       */
      public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
  
      /**
       * Returns a string representation of the first argument in the
       * radix specified by the second argument.
       *
       * <p>If the radix is smaller than {@code Character.MIN_RADIX}
       * or larger than {@code Character.MAX_RADIX}, then the radix
       * {@code 10} is used instead.
       *
       * <p>If the first argument is negative, the first element of the
       * result is the ASCII minus sign {@code '-'}
       * (<code>'&#92;u002d'</code>). If the first argument is not
       * negative, no sign character appears in the result.
       *
       * <p>The remaining characters of the result represent the magnitude
       * of the first argument. If the magnitude is zero, it is
       * represented by a single zero character {@code '0'}
       * (<code>'&#92;u0030'</code>); otherwise, the first character of
       * the representation of the magnitude will not be the zero
       * character.  The following ASCII characters are used as digits:
       *
       * <blockquote>
       *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
       * </blockquote>
       *
       * These are <code>'&#92;u0030'</code> through
       * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
       * <code>'&#92;u007a'</code>. If {@code radix} is
       * <var>N</var>, then the first <var>N</var> of these characters
       * are used as radix-<var>N</var> digits in the order shown. Thus,
       * the digits for hexadecimal (radix 16) are
       * {@code 0123456789abcdef}. If uppercase letters are
       * desired, the {@link java.lang.String#toUpperCase()} method may
       * be called on the result:
       *
       * <blockquote>
       *  {@code Long.toString(n, 16).toUpperCase()}
       * </blockquote>
       *
       * @param   i       a {@code long} to be converted to a string.
       * @param   radix   the radix to use in the string representation.
       * @return  a string representation of the argument in the specified radix.
       * @see     java.lang.Character#MAX_RADIX
       * @see     java.lang.Character#MIN_RADIX
       */
      public static String toString(long i, int radix) {
          if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
              radix = 10;
          if (radix == 10)
              return toString(i);
          char[] buf = new char[65];
          int charPos = 64;
          boolean negative = (i < 0);
  
          if (!negative) {
              i = -i;
          }
  
          while (i <= -radix) {
              buf[charPos--] = Integer.digits[(int)(-(i % radix))];
              i = i / radix;
          }
          buf[charPos] = Integer.digits[(int)(-i)];
  
          if (negative) {
              buf[--charPos] = '-';
          }
  
          return new String(buf, charPos, (65 - charPos));
      }
  
      /**
       * Returns a string representation of the {@code long}
       * argument as an unsigned integer in base&nbsp;16.
       *
       * <p>The unsigned {@code long} value is the argument plus
       * 2<sup>64</sup> if the argument is negative; otherwise, it is
       * equal to the argument.  This value is converted to a string of
       * ASCII digits in hexadecimal (base&nbsp;16) with no extra
       * leading {@code 0}s.  If the unsigned magnitude is zero, it
       * is represented by a single zero character {@code '0'}
       * (<code>'&#92;u0030'</code>); otherwise, the first character of
       * the representation of the unsigned magnitude will not be the
       * zero character. The following characters are used as
       * hexadecimal digits:
       *
       * <blockquote>
       *  {@code 0123456789abcdef}
       * </blockquote>
       *
       * These are the characters <code>'&#92;u0030'</code> through
       * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
       * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
       * the {@link java.lang.String#toUpperCase()} method may be called
       * on the result:
       *
       * <blockquote>
       *  {@code Long.toHexString(n).toUpperCase()}
       * </blockquote>
       *
       * @param   i   a {@code long} to be converted to a string.
       * @return  the string representation of the unsigned {@code long}
       *          value represented by the argument in hexadecimal
       *          (base&nbsp;16).
       * @since   JDK 1.0.2
       */
      public static String toHexString(long i) {
          return toUnsignedString(i, 4);
      }
  
      /**
       * Returns a string representation of the {@code long}
       * argument as an unsigned integer in base&nbsp;8.
       *
       * <p>The unsigned {@code long} value is the argument plus
       * 2<sup>64</sup> if the argument is negative; otherwise, it is
       * equal to the argument.  This value is converted to a string of
       * ASCII digits in octal (base&nbsp;8) with no extra leading
       * {@code 0}s.
       *
       * <p>If the unsigned magnitude is zero, it is represented by a
       * single zero character {@code '0'}
       * (<code>'&#92;u0030'</code>); otherwise, the first character of
       * the representation of the unsigned magnitude will not be the
       * zero character. The following characters are used as octal
       * digits:
       *
       * <blockquote>
       *  {@code 01234567}
       * </blockquote>
       *
       * These are the characters <code>'&#92;u0030'</code> through
       * <code>'&#92;u0037'</code>.
       *
       * @param   i   a {@code long} to be converted to a string.
       * @return  the string representation of the unsigned {@code long}
       *          value represented by the argument in octal (base&nbsp;8).
       * @since   JDK 1.0.2
       */
      public static String toOctalString(long i) {
          return toUnsignedString(i, 3);
      }
  
      /**
       * Returns a string representation of the {@code long}
       * argument as an unsigned integer in base&nbsp;2.
       *
       * <p>The unsigned {@code long} value is the argument plus
       * 2<sup>64</sup> if the argument is negative; otherwise, it is
       * equal to the argument.  This value is converted to a string of
       * ASCII digits in binary (base&nbsp;2) with no extra leading
       * {@code 0}s.  If the unsigned magnitude is zero, it is
       * represented by a single zero character {@code '0'}
       * (<code>'&#92;u0030'</code>); otherwise, the first character of
       * the representation of the unsigned magnitude will not be the
       * zero character. The characters {@code '0'}
       * (<code>'&#92;u0030'</code>) and {@code '1'}
       * (<code>'&#92;u0031'</code>) are used as binary digits.
       *
       * @param   i   a {@code long} to be converted to a string.
       * @return  the string representation of the unsigned {@code long}
       *          value represented by the argument in binary (base&nbsp;2).
       * @since   JDK 1.0.2
       */
      public static String toBinaryString(long i) {
          return toUnsignedString(i, 1);
      }
  
      /**
       * Convert the integer to an unsigned number.
       */
      private static String toUnsignedString(long i, int shift) {
          char[] buf = new char[64];
          int charPos = 64;
          int radix = 1 << shift;
          long mask = radix - 1;
          do {
              buf[--charPos] = Integer.digits[(int)(i & mask)];
              i >>>= shift;
          } while (i != 0);
          return new String(buf, charPos, (64 - charPos));
      }
  
      /**
       * Returns a {@code String} object representing the specified
       * {@code long}.  The argument is converted to signed decimal
       * representation and returned as a string, exactly as if the
       * argument and the radix 10 were given as arguments to the {@link
       * #toString(long, int)} method.
       *
       * @param   i   a {@code long} to be converted.
       * @return  a string representation of the argument in base&nbsp;10.
       */
      public static String toString(long i) {
          if (i == Long.MIN_VALUE)
              return "-9223372036854775808";
          int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
          char[] buf = new char[size];
          getChars(i, size, buf);
          return new String(0, size, buf);
      }
  
      /**
       * Places characters representing the integer i into the
       * character array buf. The characters are placed into
       * the buffer backwards starting with the least significant
       * digit at the specified index (exclusive), and working
       * backwards from there.
       *
       * Will fail if i == Long.MIN_VALUE
       */
      static void getChars(long i, int index, char[] buf) {
          long q;
          int r;
          int charPos = index;
          char sign = 0;
  
          if (i < 0) {
              sign = '-';
              i = -i;
          }
  
          // Get 2 digits/iteration using longs until quotient fits into an int
          while (i > Integer.MAX_VALUE) {
              q = i / 100;
              // really: r = i - (q * 100);
              r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
              i = q;
              buf[--charPos] = Integer.DigitOnes[r];
              buf[--charPos] = Integer.DigitTens[r];
          }
  
          // Get 2 digits/iteration using ints
          int q2;
          int i2 = (int)i;
          while (i2 >= 65536) {
              q2 = i2 / 100;
              // really: r = i2 - (q * 100);
              r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
              i2 = q2;
              buf[--charPos] = Integer.DigitOnes[r];
              buf[--charPos] = Integer.DigitTens[r];
          }
  
          // Fall thru to fast mode for smaller numbers
          // assert(i2 <= 65536, i2);
          for (;;) {
              q2 = (i2 * 52429) >>> (16+3);
              r = i2 - ((q2 << 3) + (q2 << 1));  // r = i2-(q2*10) ...
              buf[--charPos] = Integer.digits[r];
              i2 = q2;
              if (i2 == 0) break;
          }
          if (sign != 0) {
              buf[--charPos] = sign;
          }
      }
  
      // Requires positive x
      static int stringSize(long x) {
          long p = 10;
          for (int i=1; i<19; i++) {
              if (x < p)
                  return i;
              p = 10*p;
          }
          return 19;
      }
  
      /**
       * Parses the string argument as a signed {@code long} in the
       * radix specified by the second argument. The characters in the
       * string must all be digits of the specified radix (as determined
       * by whether {@link java.lang.Character#digit(char, int)} returns
       * a nonnegative value), except that the first character may be an
       * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
       * indicate a negative value or an ASCII plus sign {@code '+'}
       * (<code>'&#92;u002B'</code>) to indicate a positive value. The
       * resulting {@code long} value is returned.
       *
       * <p>Note that neither the character {@code L}
       * (<code>'&#92;u004C'</code>) nor {@code l}
       * (<code>'&#92;u006C'</code>) is permitted to appear at the end
       * of the string as a type indicator, as would be permitted in
       * Java programming language source code - except that either
       * {@code L} or {@code l} may appear as a digit for a
       * radix greater than 22.
       *
       * <p>An exception of type {@code NumberFormatException} is
       * thrown if any of the following situations occurs:
       * <ul>
       *
       * <li>The first argument is {@code null} or is a string of
       * length zero.
       *
       * <li>The {@code radix} is either smaller than {@link
       * java.lang.Character#MIN_RADIX} or larger than {@link
       * java.lang.Character#MAX_RADIX}.
       *
       * <li>Any character of the string is not a digit of the specified
       * radix, except that the first character may be a minus sign
       * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
       * '+'} (<code>'&#92;u002B'</code>) provided that the string is
       * longer than length 1.
       *
       * <li>The value represented by the string is not a value of type
       *      {@code long}.
       * </ul>
       *
       * <p>Examples:
       * <blockquote><pre>
       * parseLong("0", 10) returns 0L
       * parseLong("473", 10) returns 473L
       * parseLong("+42", 10) returns 42L
       * parseLong("-0", 10) returns 0L
       * parseLong("-FF", 16) returns -255L
       * parseLong("1100110", 2) returns 102L
       * parseLong("99", 8) throws a NumberFormatException
       * parseLong("Hazelnut", 10) throws a NumberFormatException
       * parseLong("Hazelnut", 36) returns 1356099454469L
       * </pre></blockquote>
       *
       * @param      s       the {@code String} containing the
       *                     {@code long} representation to be parsed.
       * @param      radix   the radix to be used while parsing {@code s}.
       * @return     the {@code long} represented by the string argument in
       *             the specified radix.
       * @throws     NumberFormatException  if the string does not contain a
       *             parsable {@code long}.
       */
      public static long parseLong(String s, int radix)
                throws NumberFormatException
      {
          if (s == null) {
              throw new NumberFormatException("null");
          }
  
  