/* * @(#) JavaConsts.java - Class defining Java-specific constants. * (c) 2000 Ivan Maidanski http://ivmai.chat.ru * Freeware class library sources. All rights reserved. ** * Language: Java [pure] * Tested with: JDK v1.1.6 * Last modified: 2000-12-19 14:00:00 GMT+03:00 */ /* * This software is the proprietary information of the author. ** * Permission to use, copy, and distribute this software and its * documentation for non-commercial purposes and without fee is * hereby granted provided that this copyright notice appears in all * copies. ** * This software should not be modified in any way; any found bug * should be reported to the author. ** * The author disclaims all warranties with regard to this software, * including all implied warranties of merchantability and fitness. * In no event shall the author be liable for any special, indirect * or consequential damages or any damages whatsoever resulting from * loss of use, data or profits, whether in an action of contract, * negligence or other tortuous action, arising out of or in * connection with the use or performance of this software. */ package ivmai.util; /** * Class defining Java-specific constants. ** * This class contains such the specific fundamental constants of * Java platform (defined by 'The Java Language Specification') as * the sizes, masks and limits for all Java numeric primitive types. ** * @see UnsignedInt * @see UnsignedLong * @see PseudoRandom * @see ByteVector * @see CharVector * @see DoubleVector * @see FloatVector * @see IntVector * @see LongVector * @see ShortVector ** * @version 2.0 * @author Ivan Maidanski ** * @since 1.8 */ public final class JavaConsts { /** * The size of byte primitive type in bits. ** * This is a fundamental constant of Java (8 by the * standard). Its value is the same as the result of execution of * value = 1; do { size++; } while ((value *= 2) != 0); * statement, where value is of byte type. ** * @see #BYTE_MASK * @see #MIN_BYTE * @see #MAX_BYTE * @see #CHAR_SIZE * @see #SHORT_SIZE * @see #INT_SIZE * @see #LONG_SIZE */ public static final int BYTE_SIZE = 8; /** * The size of char primitive type in bits. ** * This is a fundamental constant of Java (16 by the * standard). Its value is the same as the result of execution of * value = 1; do { size++; } while ((value *= 2) != 0); * statement, where value is of char type. * Important notes: this size is not less than * BYTE_SIZE; see also the Unicode standard. ** * @see #CHAR_LENGTH * @see #CHAR_MASK * @see #BYTE_SIZE * @see #SHORT_SIZE * @see #INT_SIZE * @see #LONG_SIZE */ public static final int CHAR_SIZE = 16; /** * The size of short primitive type in bits. ** * This is a fundamental constant of Java (16 by the * standard). Its value is the same as the result of execution of * value = 1; do { size++; } while ((value *= 2) != 0); * statement, where value is of short type. * Important notes: this size is not less than * BYTE_SIZE. ** * @see #SHORT_LENGTH * @see #SHORT_MASK * @see #MIN_SHORT * @see #MAX_SHORT * @see #BYTE_SIZE * @see #CHAR_SIZE * @see #INT_SIZE * @see #LONG_SIZE */ public static final int SHORT_SIZE = 16; /** * The size of mantissa of float primitive type in * bits. ** * This is a fundamental constant of Java (23 by the * standard). Its value is the same as the result of execution of * value = 1; while ((value *= 2) + 1 != value) size++; * statement, where value is of float type. * Important notes: this size is less than INT_SIZE; * the whole size of float type is the same as the size * of int type. ** * @see #FLOAT_M_MASK * @see #FLOAT_EXP_SIZE * @see #DOUBLE_M_SIZE * @see #INT_SIZE */ public static final int FLOAT_M_SIZE = 23; /** * The size of int primitive type in bits. ** * This is a fundamental constant of Java (32 by the * standard). Its value is the same as the result of execution of * value = 1; do { size++; } while ((value *= 2) != 0); * statement, where value is of int type. * Important notes: this size is not less than * SHORT_SIZE. ** * @see #INT_LENGTH * @see #INT_LMASK * @see #MIN_INT * @see #MAX_INT * @see #BYTE_SIZE * @see #CHAR_SIZE * @see #SHORT_SIZE * @see #LONG_SIZE * @see #FLOAT_M_SIZE */ public static final int INT_SIZE = 32; /** * The size of mantissa of double primitive type in * bits. ** * This is a fundamental constant of Java (52 by the * standard). Its value is the same as the result of execution of * value = 1; while ((value *= 2) + 1 != value) size++; * statement, where value is of double type. * Important notes: this size is less than LONG_SIZE * and not less than FLOAT_M_SIZE; the whole size of * double type is the same as the size of * long. ** * @see #DOUBLE_M_MASK * @see #DOUBLE_EXP_SIZE * @see #FLOAT_M_SIZE * @see #LONG_SIZE */ public static final int DOUBLE_M_SIZE = 52; /** * The size of long primitive type in bits. ** * This is a fundamental constant of Java (64 by the * standard). Its value is the same as the result of execution of * value = 1; do { size++; } while ((value *= 2) != 0); * statement, where value is of long type. * Important notes: this size is not less than * INT_SIZE. ** * @see #LONG_LENGTH * @see #MIN_LONG * @see #MAX_LONG * @see #BYTE_SIZE * @see #SHORT_SIZE * @see #INT_SIZE * @see #DOUBLE_M_SIZE */ public static final int LONG_SIZE = 64; /** * Unsigned 'Gold Median' constant. ** * This constant is the calculated integer value of * (sqrt(5) - 1) * (MAX_INT + 1) rounded to the * nearest prime. 'Gold Median' is used for various digest * calculations ('Multiplicative' method) as follows: * (((value ^ seed) * GOLD_MEDIAN) >>> shift), where * shift is equal to * (INT_SIZE - resultSize). ** * @see #LONG_GOLD_MEDIAN * @see #INT_SIZE * @see #INT_LMASK * @see #MAX_INT */ public static final int GOLD_MEDIAN = 0x9E3779B1; /** * Unsigned 'Gold Median' constant for long type. ** * This constant is the calculated long integer value * of (sqrt(5) - 1) * (MAX_LONG + 1) rounded to the * nearest prime. 'Gold Median' is used for various digest * calculations ('Multiplicative' method) as follows: * (((value ^ seed) * LONG_GOLD_MEDIAN) >>> shift), * where shift is equal to * (LONG_SIZE - resultSize). ** * @see #GOLD_MEDIAN * @see #LONG_SIZE * @see #MAX_LONG */ public static final long LONG_GOLD_MEDIAN = 0x9E3779B97F4A7C55L; /** * The size of exponent of float primitive type in * bits. ** * @see #FLOAT_EXP_MASK * @see #FLOAT_M_SIZE * @see #DOUBLE_EXP_SIZE * @see #INT_SIZE */ public static final int FLOAT_EXP_SIZE = INT_SIZE - FLOAT_M_SIZE - 1; /** * The size of exponent of double primitive type in * bits. ** * @see #DOUBLE_EXP_MASK * @see #DOUBLE_M_SIZE * @see #FLOAT_EXP_SIZE * @see #LONG_SIZE */ public static final int DOUBLE_EXP_SIZE = LONG_SIZE - DOUBLE_M_SIZE - 1; /** * The length of char primitive type (in bytes). ** * @see #CHAR_SIZE * @see #CHAR_MASK * @see #SHORT_LENGTH * @see #INT_LENGTH * @see #LONG_LENGTH */ public static final int CHAR_LENGTH = (CHAR_SIZE - 1) / BYTE_SIZE + 1; /** * The length of short primitive type (in bytes). ** * @see #SHORT_SIZE * @see #SHORT_MASK * @see #MIN_SHORT * @see #MAX_SHORT * @see #CHAR_LENGTH * @see #INT_LENGTH * @see #LONG_LENGTH */ public static final int SHORT_LENGTH = (SHORT_SIZE - 1) / BYTE_SIZE + 1; /** * The length of int primitive type (in bytes). ** * @see #INT_SIZE * @see #INT_LMASK * @see #MIN_INT * @see #MAX_INT * @see #CHAR_LENGTH * @see #SHORT_LENGTH * @see #LONG_LENGTH */ public static final int INT_LENGTH = (INT_SIZE - 1) / BYTE_SIZE + 1; /** * The length of long primitive type (in bytes). ** * @see #LONG_SIZE * @see #MIN_LONG * @see #MAX_LONG * @see #CHAR_LENGTH * @see #SHORT_LENGTH * @see #INT_LENGTH */ public static final int LONG_LENGTH = (LONG_SIZE - 1) / BYTE_SIZE + 1; /** * The unsigned int mask of byte type. ** * @see #BYTE_SIZE * @see #MIN_BYTE * @see #MAX_BYTE * @see #CHAR_MASK * @see #SHORT_MASK * @see #INT_LMASK */ public static final int BYTE_MASK = ~((-1 << (BYTE_SIZE - 1)) << 1); /** * The unsigned int mask of char type. ** * @see #CHAR_SIZE * @see #CHAR_LENGTH * @see #BYTE_MASK * @see #SHORT_MASK * @see #INT_LMASK */ public static final int CHAR_MASK = ~((-1 << (CHAR_SIZE - 1)) << 1); /** * The unsigned int mask of short type. ** * @see #SHORT_SIZE * @see #SHORT_LENGTH * @see #MIN_SHORT * @see #MAX_SHORT * @see #BYTE_MASK * @see #CHAR_MASK * @see #INT_LMASK */ public static final int SHORT_MASK = ~((-1 << (SHORT_SIZE - 1)) << 1); /** * The unsigned long mask of int type. ** * @see #INT_SIZE * @see #INT_LENGTH * @see #MIN_INT * @see #MAX_INT * @see #BYTE_MASK * @see #CHAR_MASK * @see #SHORT_MASK * @see #FLOAT_M_MASK * @see #FLOAT_EXP_MASK */ public static final long INT_LMASK = (-1 >>> 1) * 2L + 1L; /** * The unsigned int mask of the mantissa part of * float type. ** * @see #FLOAT_M_SIZE * @see #FLOAT_EXP_MASK * @see #DOUBLE_M_MASK * @see #INT_SIZE * @see #INT_LENGTH * @see #INT_LMASK */ public static final int FLOAT_M_MASK = ~(-1 << FLOAT_M_SIZE); /** * The unsigned int mask of the exponent part of * float type. ** * @see #FLOAT_EXP_SIZE * @see #FLOAT_M_MASK * @see #DOUBLE_EXP_MASK * @see #INT_SIZE * @see #INT_LENGTH * @see #INT_LMASK */ public static final int FLOAT_EXP_MASK = ~(-1 << FLOAT_EXP_SIZE) << FLOAT_M_SIZE; /** * The unsigned long mask of the mantissa part of * double type. ** * @see #DOUBLE_M_SIZE * @see #DOUBLE_EXP_MASK * @see #FLOAT_M_MASK * @see #LONG_SIZE * @see #LONG_LENGTH */ public static final long DOUBLE_M_MASK = ~(-1L << DOUBLE_M_SIZE); /** * The unsigned long mask of the exponent part of * double type. ** * @see #DOUBLE_EXP_SIZE * @see #DOUBLE_M_MASK * @see #FLOAT_EXP_MASK * @see #LONG_SIZE * @see #LONG_LENGTH */ public static final long DOUBLE_EXP_MASK = ~(-1L << DOUBLE_EXP_SIZE) << DOUBLE_M_SIZE; /** * The smallest byte value. ** * @see #BYTE_SIZE * @see #BYTE_MASK * @see #MAX_BYTE * @see #MIN_SHORT * @see #MIN_INT * @see #MIN_LONG */ public static final int MIN_BYTE = ~(BYTE_MASK >>> 1); /** * The largest byte value. ** * @see #BYTE_SIZE * @see #BYTE_MASK * @see #MIN_BYTE * @see #MAX_SHORT * @see #MAX_INT * @see #MAX_LONG */ public static final int MAX_BYTE = BYTE_MASK >>> 1; /** * The smallest short value. ** * @see #SHORT_SIZE * @see #SHORT_LENGTH * @see #SHORT_MASK * @see #MAX_SHORT * @see #MIN_BYTE * @see #MIN_INT * @see #MIN_LONG */ public static final int MIN_SHORT = ~(SHORT_MASK >>> 1); /** * The largest short value. ** * @see #SHORT_SIZE * @see #SHORT_LENGTH * @see #SHORT_MASK * @see #MIN_SHORT * @see #MAX_BYTE * @see #MAX_INT * @see #MAX_LONG */ public static final int MAX_SHORT = SHORT_MASK >>> 1; /** * The smallest int value. ** * @see #INT_SIZE * @see #INT_LENGTH * @see #INT_LMASK * @see #MAX_INT * @see #MIN_BYTE * @see #MIN_SHORT * @see #MIN_LONG */ public static final int MIN_INT = ~(-1 >>> 1); /** * The largest int value. ** * @see #INT_SIZE * @see #INT_LENGTH * @see #INT_LMASK * @see #MIN_INT * @see #MAX_BYTE * @see #MAX_SHORT * @see #MAX_LONG */ public static final int MAX_INT = -1 >>> 1; /** * The smallest long value. ** * @see #LONG_SIZE * @see #LONG_LENGTH * @see #MAX_LONG * @see #MIN_BYTE * @see #MIN_SHORT * @see #MIN_INT */ public static final long MIN_LONG = ~(-1L >>> 1); /** * The largest long value. ** * @see #LONG_SIZE * @see #LONG_LENGTH * @see #MIN_LONG * @see #MAX_BYTE * @see #MAX_SHORT * @see #MAX_INT */ public static final long MAX_LONG = -1L >>> 1; /** * A dummy private constructor prohibiting * instantiation of this class. */ private JavaConsts() {} }