Functions

abs
I

Returns the IEEE absolute value of a float value.

acos
I

Returns the arccosine of a float value.

asin
I

Returns the arcsine of a float value.

atan
I

Returns the arctangent of a float value.

atan2
I

Performs the 2-argument arctangent operation.

cbrt
I

Returns the cube root of a float value.

ceiling
I

Rounds a float up to the closest integral value.

cos
I

Returns the cosine of a float value.

cosh
I

Returns the hyperbolic cosine of a float value.

exp
I

Raises Euler's number to a power.

floor
I

Rounds a float down to the closest integral value.

fromBitsInt
I

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

fromHexString
I

Return the float value represented by a string.

fromString
I

Returns the float value represented by a string.

isFinite
I

Tests whether a float is finite.

isInfinite
I

Tests whether a float is infinite.

isNaN
I

Tests whether a float is NaN.

log
I

Returns the natural logarithm of a float value.

log10
I

Returns the base 10 logarithm of a float value.

max
I

Returns the maximum of zero or more float values.

min
I

Returns the minimum of zero or more float values.

pow
I

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

round
I

Rounds a float value to a specified number of digits.

sin
I

Returns the sine of a float value.

sinh
I

Returns the hyperbolic sine of a float value.

sqrt
I

Returns the square root of a float value.

sum
I

Returns the sum of zero or more float values.

tan
I

Returns the tangent of a float value.

tanh
I

Returns the hyperbolic tangent of a float value.

toBitsInt
I

Returns IEEE 64-bit binary floating point format representation of a float value as an int.

toExpString
I

Returns a string that represents x using scientific notation.

toFixedString
I

Returns a string that represents x using fixed-point notation.

toHexString
I

Returns a string that represents a float value as a hexadecimal floating point number.

abs

function abs(float x) returns float
Isolated Function

Returns the IEEE absolute value of a float value.

Parameters

  • x float
  • float value to operate on

Return Type

(float)

absolute value of parameter x

acos

function acos(float x) returns float
Isolated Function

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 parameter x in radians

asin

function asin(float x) returns float
Isolated Function

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 parameter x in radians

atan

function atan(float x) returns float
Isolated Function

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 parameter x in radians

atan2

function atan2(float y, float x) returns float
Isolated Function

Performs the 2-argument arctangent operation.

Corresponds IEEE atan2(y, x) operation.

Parameters

Return Type

(float)

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

cbrt

function cbrt(float x) returns float
Isolated Function

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 parameter x

ceiling

function ceiling(float x) returns float
Isolated Function

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 parameter x that is a mathematical integer

cos

function cos(float x) returns float
Isolated Function

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 parameter x

cosh

function cosh(float x) returns float
Isolated Function

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 parameter x

exp

function exp(float x) returns float
Isolated Function

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 parameter x

floor

function floor(float x) returns float
Isolated Function

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 parameter x that is a mathematical integer

fromBitsInt

function fromBitsInt(int x) returns float
Isolated Function

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

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)

parameter x bit pattern as a float

fromHexString

function fromHexString(string s) returns float | error
Isolated Function

Return the float value represented by a string.

parameter 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

function fromString(string s) returns float | error
Isolated Function

Returns the float value represented by a string.

parameter 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 function value:toString applied to an float.

Parameters

  • s string
  • string representation of a float

Return Type

(float | error)

float value or error

isFinite

function isFinite(float x) returns boolean
Isolated Function

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 parameter x is finite, i.e., neither NaN nor +∞ nor -∞

isInfinite

function isInfinite(float x) returns boolean
Isolated Function

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 parameter x is either +∞ or -∞

isNaN

function isNaN(float x) returns boolean
Isolated Function

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 parameter x is NaN

log

function log(float x) returns float
Isolated Function

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 parameter x

log10

function log10(float x) returns float
Isolated Function

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 parameter x

max

function max(float... xs) returns float
Isolated Function

Returns the 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 of parameter xs

min

function min(float... xs) returns float
Isolated Function

Returns the 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 of parameter xs

pow

function pow(float x, float y) returns float
Isolated Function

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

Corresponds to IEEE pow(x, y) operation.

Parameters

Return Type

(float)

x raised to the power of parameter y

round

function round(float x, int fractionDigits) returns float
Isolated Function

Rounds a float value to a specified number of digits.

Returns the float value that is an integral multiple of 10 raised to the power of -fractionDigits and closest to x. If there are two such values, choose the one whose final digit is even (this is the round-to-nearest rounding mode, which is the default for IEEE and for Ballerina). A value of fractionDigits greater than 0 thus corresponds to the number of digits after the decimal point being fractionDigits; a value of 0 for fractionDigits rounds to an integer. If x is NaN, +0, -0, +∞ or -∞, then the result is x``. MISSING[]When fractionDigits is 0, this is the same as Java Math.rint method, .NET Math.Round method and IEEE roundToIntegralTiesToEven operation Note that <int>x is the same as <int>x.round(0).

Parameters

  • x float
  • float value to operate on

  • fractionDigits int (default 0)
  • the number of digits after the decimal point

Return Type

(float)

float value closest to x that is an integral multiple of 10 raised to the power of -fractionDigits

sin

function sin(float x) returns float
Isolated Function

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 parameter x

sinh

function sinh(float x) returns float
Isolated Function

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 parameter x

sqrt

function sqrt(float x) returns float
Isolated Function

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 parameter x

sum

function sum(float... xs) returns float
Isolated Function

Returns the 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 of parameter xs, +0.0 if parameter xs is empty

tan

function tan(float x) returns float
Isolated Function

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 parameter x

tanh

function tanh(float x) returns float
Isolated Function

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 parameter x

toBitsInt

function toBitsInt(float x) returns int
Isolated Function

Returns IEEE 64-bit binary floating point format representation of a float value as an int.

Parameters

Return Type

(int)

parameter x bit pattern as an int

toExpString

function toExpString(float x, int? fractionDigits) returns string
Isolated Function

Returns a string that represents x using scientific notation. The returned string will be in the same format used by value:toString, except that it will always include an exponent and there will be exactly one digit before the decimal point. But if x is NaN or infinite, the result will be the same as value:toString. The digit before the decimal point will be zero only if all other digits are zero. This will panic if fractionDigits is less than 0. If fractionDigits is zero, there will be no decimal point. Any necessary rounding will use the roundTiesToEven rounding direction. The exponent in the result uses lower-case e, followed by a + or - sign, followed by at least two digits, and only as many more digits as are needed to represent the result. If x is zero, the exponent is zero. A zero exponent is represented with a + sign.

Parameters

  • fractionDigits int?
  • number of digits following the decimal point; () means to use the minimum number of digits required to accurately represent the value

Return Type

(string)

string representation of x in scientific notation

toFixedString

function toFixedString(float x, int? fractionDigits) returns string
Isolated Function

Returns a string that represents x using fixed-point notation. The returned string will be in the same format used by value:toString, except that it will not include an exponent. If x is NaN or infinite, the result will be the same as value:toString. This will panic if fractionDigits is less than 0. If fractionDigits is zero, there will be no decimal point. Any necessary rounding will use the roundTiesToEven rounding direction.

Parameters

  • fractionDigits int?
  • number of digits following the decimal point; () means to use the minimum number of digits required to accurately represent the value

Return Type

(string)

string representation of x in fixed-point notation

toHexString

function toHexString(float x) returns string
Isolated Function

Returns a string that represents a float value 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