This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Functions - lang.float

abs

IEEE abs operation.

acos

Returns the arccosine of a float value.

asin

Returns the arcsine of a float value.

atan

Returns the arctangent of a float value.

atan2

Performs the 2-argument arctangent operation.

cbrt

Returns the cube root of a float value.

ceiling

Rounds a float up to the closest integral value.

cos

Returns the cosine of a float value.

cosh

Returns the hyperbolic cosine of a float value.

exp

Raises Euler's number to a power.

floor

Rounds a float down to the closest integral value.

fromBitsInt

Returns the float that is represented in IEEE 64-bit floating point by x.

fromHexString

Return the float value represented by s.

fromString

Return the float value represented by s.

isFinite

Tests whether a float is finite.

isInfinite

Tests whether a float is infinite.

isNaN

Tests whether a float is NaN.

log

Returns the natural logarithm of a float value Corresponds to IEEE log operation.

log10

Returns the base 10 logarithm of a float value.

max

Maximum of zero or more float values.

min

Minimum of zero or more float values.

pow

Raises one float value to the power of another float values.

round

Round a float value to the closest integral value.

sin

Returns the sine of a float value.

sinh

Returns the hyperbolic sine of a float value.

sqrt

Returns the square root of a float value.

sum

Sum of zero or more float values.

tan

Returns the tangent of a float value.

tanh

Returns the hyperbolic tangent of a float value.

toBitsInt

Returns IEEE 64-bit binary floating point format representation of x as an int.

toHexString

Returns a string that represents x as a hexadecimal floating point number.

abs

(float x)

returns float

IEEE abs operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • absolute value of x

acos

(float x)

returns float

Returns the arccosine of a float value. Corresponds to IEEE acos operation

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • the arccosine of x in radians

asin

(float x)

returns float

Returns the arcsine of a float value. Corresponds to IEEE asin operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • the arcsine of x in radians

atan

(float x)

returns float

Returns the arctangent of a float value. Corresponds to IEEE atan operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • the arctangent of x in radians

atan2

(float y, float x)

returns float

Performs the 2-argument arctangent operation. Corresponds IEEE atan2(y, x) operation.

Parameters

  • y float
  • the y-coordinate

  • x float
  • the x-coordinate

  • Return Type

    (float)
  • the angle in radians from the positive x-axis to the point whose Cartesian coordinates are (x, y)

cbrt

(float x)

returns float

Returns the cube root of a float value. Corresponds to IEEE rootn(x, 3) operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • cube root of x

ceiling

(float x)

returns float

Rounds a float up to the closest integral value.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • smallest (closest to -∞) decimal value not less than x that is a mathematical integer

cos

(float x)

returns float

Returns the cosine of a float value. Corresponds to IEEE cos operation.

Parameters

  • x float
  • float value, specifying an angle in radians

  • Return Type

    (float)
  • the cosine of x

cosh

(float x)

returns float

Returns the hyperbolic cosine of a float value. Corresponds to IEEE cosh operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • hyperbolic cosine of x

exp

(float x)

returns float

Raises Euler's number to a power. Corresponds to IEEE exp operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • Euler's number raised to the power x

floor

(float x)

returns float

Rounds a float down to the closest integral value.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • largest (closest to +∞) float value not greater than x that is a mathematical integer.

fromBitsInt

(int x)

returns float

Returns the float that is represented in IEEE 64-bit floating point by x. All bit patterns that IEEE defines to be NaNs will all be mapped to the single float NaN value.

Parameters

  • x int
  • int value

  • Return Type

    (float)
  • x bit pattern as a float

fromHexString

(string s)

returns float | error

Return the float value represented by s. s must follow the syntax of HexFloatingPointLiteral as defined by the Ballerina specification with the following modifications

  • the HexFloatingPointLiteral may have a leading + or - sign
  • NaN is allowed
  • Infinity is allowed with an optional leading + or - sign

Parameters

  • s string
  • hexadecimal floating point hex string representation

  • Return Type

    (float | error)
  • float value or error

fromString

(string s)

returns float | error

Return the float value represented by s. s must follow the syntax of DecimalFloatingPointNumber as defined by the Ballerina specification with the following modifications

  • the DecimalFloatingPointNumber may have a leading + or - sign
  • NaN is allowed
  • Infinity is allowed with an optional leading + or - sign
  • a FloatingPointTypeSuffix is not allowed This is the inverse of value:toString applied to an float.

Parameters

  • s string
  • string representation of a float

  • Return Type

    (float | error)
  • float value or error

isFinite

(float x)

returns boolean

Tests whether a float is finite. Exactly one of isFinite, isInfinite and IsNaN will be true for any float value

Parameters

  • x float
  • the float to be tested

  • Return Type

    (boolean)
  • true if x is finite, i.e. neither NaN nor +∞ nor -∞

isInfinite

(float x)

returns boolean

Tests whether a float is infinite. Exactly one of isFinite, isInfinite and IsNaN will be true for any float value

Parameters

  • x float
  • the float to be tested

  • Return Type

    (boolean)
  • true if x is either +∞ or -∞

isNaN

(float x)

returns boolean

Tests whether a float is NaN. Exactly one of isFinite, isInfinite and IsNaN will be true for any float value.

Parameters

  • x float
  • the float to be tested

  • Return Type

    (boolean)
  • true if x is NaN

log

(float x)

returns float

Returns the natural logarithm of a float value Corresponds to IEEE log operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • natural logarithm of x

log10

(float x)

returns float

Returns the base 10 logarithm of a float value. Corresponds to IEEE log10 operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • base 10 logarithm of x

max

(float... xs)

returns float

Maximum of zero or more float values. Result is -∞ if no args NaN if any arg is NaN

Parameters

  • xs float...
  • float values to operate on

  • Return Type

    (float)
  • maximum value of all the xs

min

(float... xs)

returns float

Minimum of zero or more float values. Result is +∞ if no args Result is NaN if any arg is NaN

Parameters

  • xs float...
  • float values to operate on

  • Return Type

    (float)
  • minimum value of all the xs

pow

(float x, float y)

returns float

Raises one float value to the power of another float values. Corresponds to IEEE pow(x, y) operation.

Parameters

  • x float
  • base value

  • y float
  • the exponent

  • Return Type

    (float)
  • x raised to the power of y

round

(float x)

returns float

Round a float value to the closest integral value. Returns the float value that is a mathematical integer and closest to x. If there are two such values, choose the one that is even (this is the round-to-nearest rounding mode, which is the default for IEEE and for Ballerina). Same as Java Math.rint method Same as .NET Math.Round method IEEE roundToIntegralTiesToEven operation Note that <int>x is the same as <int>x.round()

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • closest float value to x that is a mathematical integer

sin

(float x)

returns float

Returns the sine of a float value. Corresponds to IEEE sin operation.

Parameters

  • x float
  • float value, specifying an angle in radians

  • Return Type

    (float)
  • the sine of x

sinh

(float x)

returns float

Returns the hyperbolic sine of a float value. Corresponds to IEEE sinh operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • hyperbolic sine of x

sqrt

(float x)

returns float

Returns the square root of a float value. Corresponds to IEEE squareRoot operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • square root of x

sum

(float... xs)

returns float

Sum of zero or more float values. Result is NaN if any arg is NaN

Parameters

  • xs float...
  • float values to sum

  • Return Type

    (float)
  • sum of all the xs, +0.0 if xs is empty

tan

(float x)

returns float

Returns the tangent of a float value. Corresponds to IEEE tan operation

Parameters

  • x float
  • float value, specifying an angle in radians

  • Return Type

    (float)
  • the tangent of x

tanh

(float x)

returns float

Returns the hyperbolic tangent of a float value. Corresponds to IEEE tanh operation.

Parameters

  • x float
  • float value to operate on

  • Return Type

    (float)
  • hyperbolic tangent of x

toBitsInt

(float x)

returns int

Returns IEEE 64-bit binary floating point format representation of x as an int.

Parameters

  • x float
  • float value

  • Return Type

    (int)
  • x bit pattern as an int

toHexString

(float x)

returns string

Returns a string that represents x as a hexadecimal floating point number. The returned string will comply to the grammar of HexFloatingPointLiteral in the Ballerina spec with the following modifications:

  • it will have a leading - sign if negative
  • positive infinity will be represented by Infinity
  • negative infinity will be represented by -Infinity
  • NaN will be represented by NaN The representation includes 0x for finite numbers.

Parameters

  • x float
  • float value

  • Return Type

    (string)
  • hexadecimal floating point hex string representation