Function num #

Get the numerator of a fraction. For a fraction a/b, the function returns a.

The result is always in lowest terms. For example, num(fraction(8, 6)) returns 4n because 8/6 simplifies to 4/3.

For negative fractions like -a/b or a/-b, the sign is always included in the numerator. Both forms are normalized internally, so num(fraction(-2, 3)) and num(fraction(2, -3)) both return -2.

For matrices, the function is evaluated element wise.

Syntax #

math.num(x)

Parameters #

Parameter Type Description
x Fraction | BigNumber | Array | Matrix A fraction, BigNumber, or array with fractions

Returns #

Type Description
bigint | Array | Matrix The numerator of x (in lowest terms)

Throws #

Type | Description —- | ———–

Examples #

math.num(math.fraction(2, 3))   // returns 2n
math.num(math.fraction(8, 6))   // returns 4n
math.num(math.fraction('5/8'))  // returns 5n
math.num(math.fraction(-2, 3))  // returns -2n
math.num(math.fraction(2, -3))  // returns -2n
math.num(math.bignumber('0.5'))  // returns 1n

See also #

den, fraction

History #

Version Comment
v15.2.0 Created
Fork me on GitHub