Class NumberDataType

    • Field Detail

      • MAXLONG_PLUS_ONE

        static final java.math.BigDecimal MAXLONG_PLUS_ONE
      • MINLONG_MINUS_ONE

        static final java.math.BigDecimal MINLONG_MINUS_ONE
    • Constructor Detail

      • NumberDataType

        public NumberDataType()
    • Method Detail

      • sqrt

        public NumberDataValue sqrt​(NumberDataValue result)
                             throws StandardException
        This is the sqrt method.
        Specified by:
        sqrt in interface NumberDataValue
        Parameters:
        result - The result of the previous call to this method, null if not call yet.
        Returns:
        this object's sqrt value. Null if object is null. Note: -0.0f and -0.0d returns 0.0f and 0.0d.
        Throws:
        StandardException - thrown on a negative number.
      • divide

        public NumberDataValue divide​(NumberDataValue dividend,
                                      NumberDataValue divisor,
                                      NumberDataValue result)
                               throws StandardException
        This method implements the / operator for TINYINT, SMALLINT and INTEGER. Specialized methods are not required for TINYINT and SMALLINT as the Java virtual machine always executes byte and int division as integer.
        Specified by:
        divide in interface NumberDataValue
        Parameters:
        dividend - The numerator
        divisor - The denominator
        result - The result of a previous call to this method, null if not called yet
        Returns:
        A SQLInteger containing the result of the division
        Throws:
        StandardException - Thrown on error
      • divide

        public NumberDataValue divide​(NumberDataValue dividend,
                                      NumberDataValue divisor,
                                      NumberDataValue result,
                                      int scale)
                               throws StandardException
        Suitable for integral types that ignore scale.
        Specified by:
        divide in interface NumberDataValue
        Parameters:
        dividend - The numerator
        divisor - The denominator
        result - The result of the previous call to this method, null if not called yet.
        scale - The scale of the result, for decimal type. If pass in value < 0, can calculate it dynamically.
        Returns:
        dividend / divisor
        Throws:
        StandardException - Thrown on error, if result is non-null then its value will be unchanged.
      • compare

        public final int compare​(DataValueDescriptor arg)
                          throws StandardException
        Description copied from interface: DataValueDescriptor
        Compare this Orderable with a given Orderable for the purpose of index positioning. This method treats nulls as ordered values - that is, it treats SQL null as equal to null and greater than all other values.
        Specified by:
        compare in interface DataValueDescriptor
        Parameters:
        arg - The Orderable to compare this one to.
        Returns:
        <0 - this Orderable is less than other. 0 - this Orderable equals other. >0 - this Orderable is greater than other. The code should not explicitly look for -1, or 1.
        Throws:
        StandardException - Thrown on error
      • compare

        public final boolean compare​(int op,
                                     DataValueDescriptor other,
                                     boolean orderedNulls,
                                     boolean unknownRV)
                              throws StandardException
        Description copied from interface: DataValueDescriptor
        Compare this Orderable with a given Orderable for the purpose of qualification and sorting. The caller gets to determine how nulls should be treated - they can either be ordered values or unknown values.
        Specified by:
        compare in interface DataValueDescriptor
        Overrides:
        compare in class DataType
        Parameters:
        op - Orderable.ORDER_OP_EQUALS means do an = comparison. Orderable.ORDER_OP_LESSTHAN means compare this < other. Orderable.ORDER_OP_LESSOREQUALS means compare this <= other.
        other - The DataValueDescriptor to compare this one to.
        orderedNulls - True means to treat nulls as ordered values, that is, treat SQL null as equal to null, and less than all other values. False means to treat nulls as unknown values, that is, the result of any comparison with a null is the UNKNOWN truth value.
        unknownRV - The return value to use if the result of the comparison is the UNKNOWN truth value. In other words, if orderedNulls is false, and a null is involved in the comparison, return unknownRV. This parameter is not used orderedNulls is true.
        Returns:
        true if the comparison is true (duh!)
        Throws:
        StandardException - thrown on error
      • isNegative

        protected abstract boolean isNegative()
        The isNegative abstract method. Checks to see if this.value is negative. To be implemented by each NumberDataType.
        Returns:
        A boolean. If this.value is negative, return true. For positive values or null, return false.
      • setValue

        public void setValue​(short theValue)
                      throws StandardException
        Common code to handle converting a short to this value by using the int to this value conversion. Simply calls setValue(int).
        Specified by:
        setValue in interface DataValueDescriptor
        Overrides:
        setValue in class DataType
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • setValue

        public void setValue​(byte theValue)
                      throws StandardException
        Common code to handle converting a byte to this value by using the int to this value conversion. Simply calls setValue(int).
        Specified by:
        setValue in interface DataValueDescriptor
        Overrides:
        setValue in class DataType
        Parameters:
        theValue - The value to set this DataValueDescriptor to
        Throws:
        StandardException - Thrown on error
      • typeToBigDecimal

        public int typeToBigDecimal()
        Implementation for integral types. Convert to a BigDecimal using long
        Specified by:
        typeToBigDecimal in interface DataValueDescriptor
        Overrides:
        typeToBigDecimal in class DataType
        Returns:
        Types.CHAR for String conversion through getString Types.DECIMAL for BigDecimal through getObject or Types.BIGINT for long conversion through getLong
      • objectNull

        protected final boolean objectNull​(java.lang.Object o)
      • normalizeREAL

        public static float normalizeREAL​(float v)
                                   throws StandardException
        normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.
        Throws:
        StandardException - if the value is not a number (NaN) or is infinite.
      • normalizeREAL

        public static float normalizeREAL​(double v)
                                   throws StandardException
        normalizeREAL normalizes the value, so that negative zero (-0.0) becomes positive.

        The reason for having normalizeREAL with two signatures is to avoid that normalizeREAL is accidentally called with a casted (float)<double value> since this can introduce an undetected underflow values to 0.0f.

        Throws:
        StandardException - if the value is not a number (NaN) or is infinite or on underflow (the value has magnitude too small to be represented as a float).
      • normalizeDOUBLE

        public static double normalizeDOUBLE​(double v)
                                      throws StandardException
        normalizeDOUBLE normalizes the value, so that negative zero (-0.0) becomes positive.
        Throws:
        StandardException - if v is not a number (NaN) or is infinite.
      • useDB2Limits

        private static boolean useDB2Limits()
                                     throws StandardException
        Controls use of old DB2 limits (DERBY-3398).
        Returns:
        false if dictionary is new enough, see DD_Version.
        Throws:
        StandardException
      • getContextOrNull

        private static Context getContextOrNull​(java.lang.String contextID)
        Privileged lookup of a Context. Must be private so that user code can't call this entry point.