net.sf.saxon.value

Class DoubleValue

public final class DoubleValue extends NumericValue

A numeric (double precision floating point) value
Field Summary
static PatternnonExponentialPattern
static DoubleValueNaN
static DoubleValueNEGATIVE_ZERO
static DoubleValueONE
static DoubleValueZERO
Constructor Summary
DoubleValue(CharSequence val)
Constructor supplying a string
DoubleValue(double value)
Constructor supplying a double
DoubleValue(double value, AtomicType type)
Constructor supplying a double and an AtomicType, for creating a value that belongs to a user-defined subtype of xs:double.
Method Summary
NumericValueabs()
Get the absolute value as defined by the XPath abs() function
NumericValueceiling()
Implement the XPath ceiling() function
intcompareTo(long other)
Compare the value to a long.
ConversionResultconvertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type
AtomicValuecopyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label
static CharSequencedoubleToString(double value)
Internal method used for conversion of a double to a string
booleaneffectiveBooleanValue()
Get the effective boolean value
NumericValuefloor()
Implement the XPath floor() function
CharSequencegetCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema.
doublegetDoubleValue()
Return this numeric value as a double
CharSequencegetPrimitiveStringValue()
Convert the double to a string according to the XPath 2.0 rules
BuiltInAtomicTypegetPrimitiveType()
Determine the primitive type of the value.
ComparablegetSchemaComparable()
Get an object that implements XML Schema comparison semantics
inthashCode()
Get the hashCode.
booleanisIdentical(Value v)
Determine whether two atomic values are identical, as determined by XML Schema rules.
booleanisNaN()
Test whether the value is the double/float value NaN
booleanisWholeNumber()
Determine whether the value is a whole number, that is, whether it compares equal to some integer
static voidmain(String[] args)
NumericValuenegate()
Negate the value
static voidprintInternalForm(double d)
Diagnostic method: print the sign, exponent, and significand
NumericValueround()
Implement the XPath round() function
NumericValueroundHalfToEven(int scale)
Implement the XPath round-to-half-even() function
doublesignum()
Determine whether the value is negative, zero, or positive

Field Detail

nonExponentialPattern

static Pattern nonExponentialPattern

NaN

public static final DoubleValue NaN

NEGATIVE_ZERO

public static final DoubleValue NEGATIVE_ZERO

ONE

public static final DoubleValue ONE

ZERO

public static final DoubleValue ZERO

Constructor Detail

DoubleValue

public DoubleValue(CharSequence val)
Constructor supplying a string

Parameters: val the string representation of the double value, conforming to the XML Schema lexical representation of xs:double, with leading and trailing spaces permitted

Throws: ValidationException if the string does not have the correct lexical form for a double. Note that the error will contain no error code or context information.

DoubleValue

public DoubleValue(double value)
Constructor supplying a double

Parameters: value the value of the NumericValue

DoubleValue

public DoubleValue(double value, AtomicType type)
Constructor supplying a double and an AtomicType, for creating a value that belongs to a user-defined subtype of xs:double. It is the caller's responsibility to ensure that the supplied value conforms to the supplied type.

Parameters: value the value of the NumericValue type the type of the value. This must be a subtype of xs:double, and the value must conform to this type. The methosd does not check these conditions.

Method Detail

abs

public NumericValue abs()
Get the absolute value as defined by the XPath abs() function

Returns: the absolute value

Since: 9.2

ceiling

public NumericValue ceiling()
Implement the XPath ceiling() function

compareTo

public int compareTo(long other)
Compare the value to a long.

Parameters: other the value to be compared with

Returns: -1 if this is less, 0 if this is equal, +1 if this is greater or if this is NaN

convertPrimitive

public ConversionResult convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type

Parameters: requiredType an integer identifying the required atomic type validate true if the supplied value must be validated, false if the caller warrants that it is valid context the XPath dynamic context

Returns: an AtomicValue, a value of the required type

copyAsSubType

public AtomicValue copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label

Parameters: typeLabel the type label of the new copy. The caller is responsible for checking that the value actually conforms to this type.

doubleToString

public static CharSequence doubleToString(double value)
Internal method used for conversion of a double to a string

Parameters: value the actual value

Returns: the value converted to a string, according to the XPath casting rules.

effectiveBooleanValue

public boolean effectiveBooleanValue()
Get the effective boolean value

Returns: the effective boolean value (true unless the value is zero or NaN)

floor

public NumericValue floor()
Implement the XPath floor() function

getCanonicalLexicalRepresentation

public CharSequence getCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema. This is not always the same as the result of casting to a string according to the XPath rules. For xs:double, the canonical representation always uses exponential notation.

getDoubleValue

public double getDoubleValue()
Return this numeric value as a double

Returns: the value as a double

getPrimitiveStringValue

public CharSequence getPrimitiveStringValue()
Convert the double to a string according to the XPath 2.0 rules

Returns: the string value

getPrimitiveType

public BuiltInAtomicType getPrimitiveType()
Determine the primitive type of the value. This delivers the same answer as getItemType().getPrimitiveItemType(). The primitive types are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration, and xs:untypedAtomic. For external objects, the result is AnyAtomicType.

getSchemaComparable

public Comparable getSchemaComparable()
Get an object that implements XML Schema comparison semantics

hashCode

public int hashCode()
Get the hashCode. This must conform to the rules for other NumericValue hashcodes

See Also: NumericValue

isIdentical

public boolean isIdentical(Value v)
Determine whether two atomic values are identical, as determined by XML Schema rules. This is a stronger test than equality (even schema-equality); for example two dateTime values are not identical unless they are in the same timezone.

Note that even this check ignores the type annotation of the value. The integer 3 and the short 3 are considered identical, even though they are not fully interchangeable. "Identical" means the same point in the value space, regardless of type annotation.

NaN is identical to itself.

Parameters: v the other value to be compared with this one

Returns: true if the two values are identical, false otherwise.

isNaN

public boolean isNaN()
Test whether the value is the double/float value NaN

isWholeNumber

public boolean isWholeNumber()
Determine whether the value is a whole number, that is, whether it compares equal to some integer

main

public static void main(String[] args)

negate

public NumericValue negate()
Negate the value

printInternalForm

public static void printInternalForm(double d)
Diagnostic method: print the sign, exponent, and significand

Parameters: d the double to be diagnosed

round

public NumericValue round()
Implement the XPath round() function

roundHalfToEven

public NumericValue roundHalfToEven(int scale)
Implement the XPath round-to-half-even() function

signum

public double signum()
Determine whether the value is negative, zero, or positive

Returns: -1 if negative, 0 if zero (including negative zero), +1 if positive, NaN if NaN