An IEEE 754 64-bit floating point number. A Float is capable of approximately representing numeric values between:

  • 2-1022, approximately 1.79769×10308, and
  • (2-2-52)×21023, approximately 5×10-324.

Zero is represented by distinct instances +0.0, -0.0, but these instances are equal. -0.0 can be distinguished from +0.0 using f == 0.0 && f.strictlyNegative.

In addition, the following special values exist:

As required by the IEEE standard no undefined value is equal to any other value, nor even to itself. Thus, the definition of equals() for Float violates the general contract defined by Object.equals().

A floating point value with a zero fractionalPart is considered equal to its integer part.

Literal floating point values are written with a decimal point and, optionally, a magnitude or exponent:

1.0
1.0E6
1.0M
1.0E-6
1.0u

In the case of a fractional magnitude, the decimal point is optional. Underscores may be used to group digits into groups of three.

no subtypes hierarchy

Constructors
FloatSource Codeshared Float(Float float)
Attributes
absoluteSee magnitude
finiteSource Codeshared Boolean finite

Determines whether this value is finite. Produces false for infinity, -infinity, and undefined.

See also infinite, infinity
fractionalPartSource Codeshared actual Float fractionalPart

The fractional part of this number, after truncation of the integral part. For Integral numeric types, the fractional part is always zero.

hashSource Codeshared actual Integer hash

A platform-dependent hash code for this Float.

Refines Object.hash
infiniteSource Codeshared Boolean infinite

Determines whether this value is infinite in magnitude. Produces true for infinity and -infinity. Produces false for a finite number, +0.0, -0.0, or undefined.

See also infinity, finite
integerSource Codeshared Integer integer

This value, represented as an Integer, after truncation of its fractional part, if such a representation is possible.

Throws
Since 1.1.0
magnitudeSource Codeshared actual Float magnitude

The magnitude of this number, defined for any instance x as:

  • -x if x<0, or
  • x otherwise,

where 0 is the additive identity. Hence:

  • x.magnitude >= 0 for any x, and
  • x.magnitude == 0 if and only if x==0.
Aliases: absolute
negatedSource Codeshared actual Float negated

The additive inverse of this value.

negativeSource Codeshared actual Boolean negative

Determines if this value is a negative number or -infinity. Produces false for a positive number, +0.0, -0.0, or undefined.

notANumberSee undefined
positiveSource Codeshared actual Boolean positive

Determines if this value is a positive number or infinity. Produces false for a negative number, +0.0, -0.0, or undefined.

signSource Codeshared actual Integer sign

The sign of this value. Produces 1 for a positive number or infinity. Produces -1 for a negative number or -infinity. Produces 0.0 for +0.0, -0.0, or undefined.

Refines Number.sign
strictlyNegativeSource Codeshared Boolean strictlyNegative

Determines if this value is a negative number, -0.0, or -infinity. Produces false for a positive number, +0.0, or undefined.

strictlyPositiveSource Codeshared Boolean strictlyPositive

Determines if this value is a positive number, +0.0, or infinity. Produces false for a negative number, -0.0, or undefined.

stringSource Codeshared actual String string

A string representing this floating point number.

  • "NaN", for any undefined value
  • "Infinity", for infinity,
  • "-Infinity", for -infinity, or,
  • a Ceylon floating point literal that evaluates to this floating point number, for example, "1.0", "-0.0", or "1.5E10".
See also formatFloat()
undefinedSource Codeshared Boolean undefined

Determines whether this value is undefined. The IEEE standard denotes undefined values NaN (an abbreviation of Not a Number). Undefined values include:

  • indeterminate forms including 0.0/0.0, infinity/infinity, 0.0*infinity, and infinity-infinity, along with
  • complex numbers like sqrt(-1.0) and log(-1.0).

An undefined value has the property that it is not equal (==) to itself, and as a consequence the undefined value cannot sensibly be used in most collections.

If x is an undefined Float, then:

  • x==x evaluates to false
  • x!=x evaluates to true, and
  • x>x, x<x, x>=x, x<=x all evaluate to false.
See also compare()
Aliases: notANumber
wholePartSource Codeshared actual Float wholePart

The integral value of the number after truncation of the fractional part. For Integral numeric types, the integral value of a number is the number itself.

Inherited Attributes
Attributes inherited from: Object
Attributes inherited from: Invertible<Other>
Attributes inherited from: Number<Other>
Methods
compareSource Codeshared actual Comparison compare(Float other)

Compare this value to the given value, where infinity is considered greater than every defined, finite value, and -infinity is considered smaller than every defined, finite value, and undefined values are considered incomparable.

Note that if x is an undefined Float and y is any Float that is not undefined, then:

  • x<=>y produces an exception when evaluated, but
  • x>y, x<y, x>=y, x<=y, and x==y all evaluate to false.
Throws
Refines Number.compare ultimately refines Comparable.compare
dividedSource Codeshared actual Float divided(Float other)

The quotient obtained by dividing this number by the given number. For integral numeric types, this operation rounds toward 0, the additive identity, and results in a remainder.

When the given divisor is exactly 0, the additive identity, the behavior depends on the numeric type:

  • For some numeric types, including Integer, division by 0 results in an exception.
  • For others, including Float, it results in a special value of the type, for example, infinity.
equalsSource Codeshared actual Boolean equals(Object that)

Determines if the given object is equal to this Float, that is, if:

  • the given object is also a Float,
  • neither this value nor the given value is undefined, and either
  • both values are infinite and have the same sign, or both represent the same finite floating point value as defined by the IEEE specification.

Or if:

  • the given object is an Integer,
  • this value is neither undefined, nor infinite,
  • the fractionalPart of this value equals 0.0,
  • the integer part of this value equals the given integer, and
  • the given integer is between -253 and 253 (exclusive).
formatSource Codeshared String format(Float float, Integer minDecimalPlaces = 1, Integer maxDecimalPlaces = ..., Character decimalSeparator = ..., Character? thousandsSeparator = null)

The string decimal representation of the given floating point number. If the given number is negative, the string representation will begin with -. The whole part and fractional parts of the number are separated by a . decimal point. Digits consist of decimal digits 0 to 9.

The number of decimal places following the decimal point is controlled by the parameters minDecimalPlaces and maxDecimalPlaces, which default to 1 and 9 respectively, so that by default the string representation always contains a decimal point, and never contains more than nine decimal places. The decimal representation is rounded so that the number of decimal places never exceeds the specified maximum.

For example:

  • formatFloat(1234.1234) is "1234.1234"
  • formatFloat(0.1234) is "0.1234"
  • formatFloat(1234.0) is "1234.0"
  • formatFloat(1234.0,0) is "1234"
  • formatFloat(1234.1234,6) is "1234.123400"
  • formatFloat(1234.1234,0,2) is "1234.12"
  • formatFloat(1234.123456,0,5) is "1234.12346"
  • formatFloat(0.0001,2,2) is "0.00"
  • formatFloat(0.0001,0,2) is "0"

Finally:

  • formatFloat(-0.0) is "0.0",
  • formatFloat(0.0/0) is "NaN",
  • formatFloat(1.0/0) is "Infinity", and
  • formatFloat(-1.0/0) is "-Infinity".

This function never produces a representation involving scientific notation.

Parameters:
  • float

    The floating point value to format.

  • minDecimalPlaces = 1

    The minimum number of allowed decimal places.

    If minDecimalPlaces<=0, the result may have no decimal point.

  • maxDecimalPlaces = 9

    The maximum number of allowed decimal places.

    If maxDecimalPlaces<=0, the result always has no decimal point.

  • decimalSeparator = '.'

    The character to use as the decimal separator.

    decimalSeparator may not be '-' or a digit as defined by the Unicode general category Nd.

  • thousandsSeparator = null

    If not null, thousandsSeparator will be used to separate each group of three digits, starting immediately to the left of the decimal separator.

    thousandsSeparator may not be equal to the decimalSeparator and may not be '-' or a digit as defined by the Unicode general category Nd.

Since 1.3.1
largerThanSource Codeshared actual Boolean largerThan(Float other)

Determines if this value is strictly larger than the given value, where infinity is considered greater than every defined, finite value, and -infinity is considered smaller than every defined, finite value. Evaluates to false if this value, the given value, or both are undefined.

minusSource Codeshared actual Float minus(Float other)

The difference between this number and the given number. Must produce the value x + -y.

notLargerThanSource Codeshared actual Boolean notLargerThan(Float other)

Determines if this value is smaller than or equal to the given value, where infinity is considered greater than every defined, finite value, and -infinity is considered smaller than every defined, finite value. Evaluates to false if this value, the given value, or both are undefined.

notSmallerThanSource Codeshared actual Boolean notSmallerThan(Float other)

Determines if this value is larger than or equal to the given value, where infinity is considered greater than every defined, finite value, and -infinity is considered smaller than every defined, finite value. Evaluates to false if this value, the given value, or both are undefined.

parseSource Codeshared Float|ParseException parse(String string)

The Float value of the given string representation of a decimal floating point number, or null if the string does not represent a decimal floating point number.

If the given string representation contains more digits than can be represented by a Float, then the least significant digits are ignored.

The syntax accepted by this method is the same as the syntax for a Float literal in the Ceylon language except that it may optionally begin with a sign character (+ or -) and may not contain grouping underscore characters. That is, an optional sign character, followed by a string of decimal digits, followed by an optional decimal point and string of decimal digits, followed by an optional decimal exponent, for example, e+10 or E-5, or SI magnitude, k, M, G, T, P, m, u, n, p, or f.

Float: Sign? Digits ('.' Digits)? (Magnitude|Exponent) Sign: '+' | '-' Magnitude: 'k' | 'M' | 'G' | 'T' | 'P' | 'm' | 'u' | 'n' | 'p' | 'f' Exponent: ('e'|'E') Sign? Digits Digits: ('0'..'9')+

Since 1.3.1
plusSource Codeshared actual Float plus(Float other)

The result of adding the given value to this value. This operation should never perform any kind of mutation upon either the receiving value or the argument value.

For any two instances x and y of a type that implements Summable, x.plus(y) may be written as:

x + y
plusIntegerSource Codeshared actual Float plusInteger(Integer integer)

The result of adding this number to the given Integer.

powerSource Codeshared actual Float power(Float other)

The result of raising this number to the given floating point power, where, following the definition of the IEEE pow() function, the following indeterminate forms all evaluate to 1.0:

  • 0.0^0.0,
  • infinity^0.0 and (-infinity)^0.0,
  • 1.0^infinity and (-1.0)^infinity.

Furthermore:

  • 0.0^infinity evaluates to 0.0, and
  • 0.0^(-infinity) evaluates to infinity.

If this is a negative number, and the given power has a nonzero fractionalPart, the result is undefined.

For any negative power y<0.0:

  • 0.0^y evaluates to infinity,
  • (-0.0)^y evaluates to -infinity, and
  • for any nonzero floating point number x, x^y evaluates to 1.0/x^(-y).
powerOfIntegerSource Codeshared actual Float powerOfInteger(Integer integer)

The result of raising this number to the given integer power, where the following indeterminate forms evaluate to 1.0:

  • 0.0^0,
  • infinity^0 and (-infinity)^0.

For any negative integer power n<0:

  • 0.0^n evaluates to infinity,
  • (-0.0)^n evaluates to -infinity, and
  • for any nonzero floating point number x, x^n evaluates to 1.0/x^(-n).
smallerThanSource Codeshared actual Boolean smallerThan(Float other)

Determines if this value is strictly smaller than the given value, where infinity is considered greater than every defined, finite value, and -infinity is considered smaller than every defined, finite value. Evaluates to false if this value, the given value, or both are undefined.

timesSource Codeshared actual Float times(Float other)

The product of this number and the given number.

timesIntegerSource Codeshared actual Float timesInteger(Integer integer)

The result of multiplying this number by the given Integer.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Comparable<Other>
Methods inherited from: Exponentiable<This,Other>
Methods inherited from: Invertible<Other>
Methods inherited from: Number<Other>
Methods inherited from: Numeric<Other>
Methods inherited from: Summable<Other>