Functions - lang.float

abs

IEEE abs operation.

acos

IEEE acos operation

asin

IEEE asin operation

atan

IEEE atan operation

atan2

IEEE atan2(y, x) operation

cbrt

Cube root. IEEE rootn(x, 3)

ceiling

Smallest (closest to -∞) floating point value not less than x that is a mathematical integer

cos

IEEE cos operation

cosh

IEEE cosh operation

exp

IEEE exp operation

floor

Largest (closest to +∞) floating point value not greater than x that is a mathematical integer

fromBitsInt

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.

fromHexString

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
fromString

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.
isFinite

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

isInfinite

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

isNaN

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

log

Natural logarithm. IEEE log operation

log10

Base 10 log. IEEE log10 operation

max

Maximum of all the arguments. (positive)∞ if no args NaN if any arg is NaN

min

Minimum of all the arguments. ∞ if no args NaN if any arg is NaN

pow

x to the power of y. IEEE pow(x, y)

round

Floating point value that is a mathematical integer and closest to x. If there are two such integers, 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()

sin

IEEE sin operation

sinh

IEEE sinh operation

sqrt

IEEE squareRoot operation.

sum

Sum of all the arguments. (positive)0.0 if no args NaN if any arg is NaN

tan

IEEE tan operation

tanh

IEEE tanh operation

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. 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.

abs

(float x)

returns float

IEEE abs operation.

Parameters

  • x float
  • whose absolute value is to be determined

  • Return Type

    (float)
  • absolute value of the argument

acos

(float x)

returns float

IEEE acos operation

Parameters

  • Return Type

    (float)
  • the arc cosine of the argument

asin

(float x)

returns float

IEEE asin operation

Parameters

  • Return Type

    (float)
  • the arc sin of the argument

atan

(float x)

returns float

IEEE atan operation

Parameters

  • Return Type

    (float)
  • the arc tan of the argument

atan2

(float y, float x)

returns float

IEEE atan2(y, x) operation

Parameters

  • y float
  • the ordinate coordinate

  • x float
  • the abscissa coordinate

  • Return Type

    (float)
  • the angle component in polar coordinate

cbrt

(float x)

returns float

Cube root. IEEE rootn(x, 3)

Parameters

  • x float
  • value to performe cube root operation on

  • Return Type

    (float)
  • cube root of the argument

ceiling

(float x)

returns float

Smallest (closest to -∞) floating point value not less than x that is a mathematical integer

Parameters

  • x float
  • value to performe ceiling on

  • Return Type

    (float)
  • integer ceiling value of the argument in float

cos

(float x)

returns float

IEEE cos operation

Parameters

  • x float
  • an angle, in radians

  • Return Type

    (float)
  • the cos of the argument

cosh

(float x)

returns float

IEEE cosh operation

Parameters

  • x float
  • the number to take cosh

  • Return Type

    (float)
  • hyperbolic cos of x

exp

(float x)

returns float

IEEE exp operation

Parameters

  • Return Type

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

floor

(float x)

returns float

Largest (closest to +∞) floating point value not greater than x that is a mathematical integer

Parameters

  • x float
  • whose value to be floored

  • Return Type

    (float)
  • floored value

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 +∞ nor -∞

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

Natural logarithm. IEEE log operation

Parameters

  • x float
  • value to take log

  • Return Type

    (float)
  • natural logarithm of x

log10

(float x)

returns float

Base 10 log. IEEE log10 operation

Parameters

  • x float
  • value to take log

  • Return Type

    (float)
  • base 10 logarithm of x

max

(float[] xs)

returns float

Maximum of all the arguments. (positive)∞ if no args NaN if any arg is NaN

Parameters

  • xs float[]
  • parameters to check for max value

  • Return Type

    (float)
  • maximum value of all provided values

min

(float[] xs)

returns float

Minimum of all the arguments. ∞ if no args NaN if any arg is NaN

Parameters

  • xs float[]
  • parameters to check for min value

  • Return Type

    (float)
  • minimum value of all provided values

pow

(float x, float y)

returns float

x to the power of y. IEEE pow(x, y)

Parameters

  • Return Type

    (float)
  • x raise to the power of y

round

(float x)

returns float

Floating point value that is a mathematical integer and closest to x. If there are two such integers, 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
  • whose value to be rounded

  • Return Type

    (float)
  • rounded value

sin

(float x)

returns float

IEEE sin operation

Parameters

  • x float
  • an angle, in radians

  • Return Type

    (float)
  • the sin of the argument

sinh

(float x)

returns float

IEEE sinh operation

Parameters

  • x float
  • the number to take sinh

  • Return Type

    (float)
  • hyperbolic sin of x

sqrt

(float x)

returns float

IEEE squareRoot operation.

Parameters

  • x float
  • value to performe squareRoot operation on

  • Return Type

    (float)
  • squareRoot of the argument

sum

(float[] xs)

returns float

Sum of all the arguments. (positive)0.0 if no args NaN if any arg is NaN

Parameters

  • xs float[]
  • float numbers to sum

  • Return Type

    (float)
  • sum of the parameters

tan

(float x)

returns float

IEEE tan operation

Parameters

  • x float
  • an angle, in radians

  • Return Type

    (float)
  • the tan of the argument

tanh

(float x)

returns float

IEEE tanh operation

Parameters

  • x float
  • the number to take tanh

  • 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

  • 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

  • Return Type

    (string)
  • hexadecimal floating point hex string representation