Libraries
Rational Source Code
 previous   up   next 

Types
rational
Rational numbers represented with 'integer' numerator and denominator.

rational

const type: rational

Rational numbers represented with 'integer' numerator and denominator. The values of the type rational are finite and periodical decimal numbers. Rational literals do not exist. The result of a rational operation is undefined if it overflows.


Operator Summary
rational
(in integer: numerator) / (in integer: denominator)
Create a rational number from its numerator and denominator.
rational
+ (in rational: number)
Plus sign for rational numbers.
rational
- (in rational: number)
Minus sign, negate a rational number.
rational
(in rational: summand1) + (in rational: summand2)
Add two rational numbers.
rational
(in rational: minuend) - (in rational: subtrahend)
Compute the subtraction of two rational numbers.
rational
(in rational: factor1) * (in rational: factor2)
Multiply two rational numbers.
rational
(in rational: dividend) / (in rational: divisor)
Compute the division of two rational numbers.
void
(inout rational: number) +:= (in rational: delta)
Increment a rational number by a delta.
void
(inout rational: number) -:= (in rational: delta)
Decrement a rational number by a delta.
void
(inout rational: number) *:= (in rational: factor)
Multiply a rational number by a factor and assign the result back to number.
void
(inout rational: number) /:= (in rational: divisor)
Divide a rational number by a divisor and assign the result back to number.
rational
(in rational: base) ** (in integer: exponent)
Compute the exponentiation of a rational base with an integer exponent.
boolean
(in rational: number1) = (in rational: number2)
Check if two rational numbers are equal.
boolean
(in rational: number1) <> (in rational: number2)
Check if two rational numbers are not equal.
boolean
(in rational: number1) < (in rational: number2)
Check if number1 is less than number2.
boolean
(in rational: number1) > (in rational: number2)
Check if number1 is greater than number2.
boolean
(in rational: number1) <= (in rational: number2)
Check if number1 is less than or equal to number2.
boolean
(in rational: number1) >= (in rational: number2)
Check if number1 is greater than or equal to number2.
rational
(attr rational) conv (in integer: number)
Return the conversion of an integer to a rational.
string
(in rational: number) digits (in integer: precision)
Convert a rational number to a string in decimal fixed point notation.
string
(in rational: number) sci (in integer: precision)
Convert a rational number to a string in scientific notation.
rational
(attr rational) parse (in string: stri)
Convert a string to a rational number.

Function Summary
integer
compare (in rational: number1, in rational: number2)
Compare two rational numbers.
integer
hashCode (in rational: number)
Compute the hash value of a rational number.
rational
rat (in integer: number)
Return the conversion of an integer to a rational.
rational
rational (in integer: number)
Return the conversion of an integer to a rational.
rational
abs (in rational: number)
Compute the absolute value of a rational number.
integer
floor (in rational: number)
Return a rational number truncated towards negative infinity.
integer
ceil (in rational: number)
Return a rational number rounded up towards positive infinity.
integer
trunc (in rational: number)
Return a rational number truncated towards zero.
integer
round (in rational: number)
Round a rational number to the nearest integer.
rational
round10 (in rational: number, in integer: precision)
Round a rational number with a decimal precision.
string
str (in rational: number)
Convert a rational number to a string.
string
fraction (in rational: number)
Convert a rational to a string with a fraction.
rational
rational (in var string: stri)
Convert a string to a rational number.

Operator Detail

/

const func rational: (in integer: numerator) / (in integer: denominator)

Create a rational number from its numerator and denominator.

Returns:
the created rational value.

+

const func rational: + (in rational: number)

Plus sign for rational numbers.

Returns:
its operand unchanged.

-

const func rational: - (in rational: number)

Minus sign, negate a rational number.

Returns:
the negated value of the number.

+

const func rational: (in rational: summand1) + (in rational: summand2)

Add two rational numbers.

Returns:
the sum of the two numbers.

-

const func rational: (in rational: minuend) - (in rational: subtrahend)

Compute the subtraction of two rational numbers.

Returns:
the difference of the two numbers.

*

const func rational: (in rational: factor1) * (in rational: factor2)

Multiply two rational numbers.

Returns:
the product of the two numbers.

/

const func rational: (in rational: dividend) / (in rational: divisor)

Compute the division of two rational numbers.

Returns:
the quotient of the division.
Raises:
NUMERIC_ERROR - If a division by zero occurs.

+:=

const proc: (inout rational: number) +:= (in rational: delta)

Increment a rational number by a delta.


-:=

const proc: (inout rational: number) -:= (in rational: delta)

Decrement a rational number by a delta.


*:=

const proc: (inout rational: number) *:= (in rational: factor)

Multiply a rational number by a factor and assign the result back to number.


/:=

const proc: (inout rational: number) /:= (in rational: divisor)

Divide a rational number by a divisor and assign the result back to number.


**

const func rational: (in rational: base) ** (in integer: exponent)

Compute the exponentiation of a rational base with an integer exponent.

Returns:
the result of the exponentiation.

=

const func boolean: (in rational: number1) = (in rational: number2)

Check if two rational numbers are equal.

Returns:
TRUE if both numbers are equal, FALSE otherwise.

<>

const func boolean: (in rational: number1) <> (in rational: number2)

Check if two rational numbers are not equal.

Returns:
FALSE if both numbers are equal, TRUE otherwise.

<

const func boolean: (in rational: number1) < (in rational: number2)

Check if number1 is less than number2.

Returns:
TRUE if number1 is less than number2, FALSE otherwise.

>

const func boolean: (in rational: number1) > (in rational: number2)

Check if number1 is greater than number2.

Returns:
TRUE if number1 is greater than number2, FALSE otherwise.

<=

const func boolean: (in rational: number1) <= (in rational: number2)

Check if number1 is less than or equal to number2.

Returns:
TRUE if number1 is less than or equal to number2, FALSE otherwise.

>=

const func boolean: (in rational: number1) >= (in rational: number2)

Check if number1 is greater than or equal to number2.

Returns:
TRUE if number1 is greater than or equal to number2, FALSE otherwise.

conv

const func rational: (attr rational) conv (in integer: number)

Return the conversion of an integer to a rational.


digits

const func string: (in rational: number) digits (in integer: precision)

Convert a rational number to a string in decimal fixed point notation. The number is rounded to the specified number of digits (precision). Halfway cases are rounded away from zero. Except for a precision of zero the representation has a decimal point and at least one digit before and after the decimal point. Negative numbers are preceded by a minus sign (e.g.: "-1.25"). If all digits in the result are 0 a possible negative sign is omitted.

1/64 digits 7     returns "0.0156250"
1/64 digits 4     returns "0.0156"
1/64 digits 2     returns "0.02"
355/113 digits 6  returns "3.141593"
22/7 digits 0     returns "3"
-1/2 digits 1     returns "-1"
1/0 digits 5      returns "Infinity"
-1/0 digits 6     returns "-Infinity"
0/0 digits 7      returns "NaN"
-1/2048 digits 3  returns "0.000"
Parameters:
precision - Number of digits after the decimal point. If the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If the precision is negative.

sci

const func string: (in rational: number) sci (in integer: precision)

Convert a rational number to a string in scientific notation. Scientific notation uses a decimal significand and a decimal exponent. The significand has an optional sign and exactly one digit before the decimal point. The fractional part of the significand is rounded to the specified number of digits (precision). Halfway cases are rounded away from zero. The fractional part is followed by the letter e and an exponent, which is always signed. The value zero is never written with a negative sign.

1/64 sci 4     returns "1.5625e-2"
1/64 sci 3     returns "1.563e-2"
1/64 sci 2     returns "1.56e-2"
355/113 sci 6  returns "3.141593e+0"
22/7 sci 0     returns "3e+0"
-1/2 sci 1     returns "-5.0e-1"
1/0 sci 5      returns "Infinity"
-1/0 sci 6     returns "-Infinity"
0/0 sci 7      returns "NaN"
-1/2048 sci 3  returns "-4.883e-4"
-0/1 sci 2     returns "0.00e+0"
Parameters:
precision - Number of digits after the decimal point. If the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If the precision is negative.

parse

const func rational: (attr rational) parse (in string: stri)

Convert a string to a rational number. The string must contain a fraction (e.g.: "3/5") or a decimal number (e.g.: "1.25"). In a fraction numerator and denominator are separated with a slash (/). A decimal number can have repeating decimals, which are enclosed in parentheses ("e.g.: "0.(3)"). The repeating decimals are not allowed to start before the decimal point.

rational parse "3/5"         returns   3 /   5
rational parse "1.25"        returns   5 /   4
rational parse "0.(3)"       returns   1 /   3
rational parse "1.23(45)"    returns 679 / 550
rational parse "3.(142857)"  returns  22 /   7
rational parse "0.(846153)"  returns  11 /  13
Returns:
the rational result of the conversion.
Raises:
RANGE_ERROR - If stri contains not a valid rational value.

Function Detail

compare

const func integer: compare (in rational: number1, in rational: number2)

Compare two rational numbers.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in rational: number)

Compute the hash value of a rational number.

Returns:
the hash value.

rat

const func rational: rat (in integer: number)

Return the conversion of an integer to a rational.


rational

const func rational: rational (in integer: number)

Return the conversion of an integer to a rational.


abs

const func rational: abs (in rational: number)

Compute the absolute value of a rational number.

Returns:
the absolute value.

floor

const func integer: floor (in rational: number)

Return a rational number truncated towards negative infinity.


ceil

const func integer: ceil (in rational: number)

Return a rational number rounded up towards positive infinity.


trunc

const func integer: trunc (in rational: number)

Return a rational number truncated towards zero.


round

const func integer: round (in rational: number)

Round a rational number to the nearest integer. Halfway cases are rounded away from zero.

Returns:
the rounded value.

round10

const func rational: round10 (in rational: number, in integer: precision)

Round a rational number with a decimal precision. Halfway cases are rounded away from zero.

Returns:
the rounded value.

str

const func string: str (in rational: number)

Convert a rational number to a string. The number is converted to a string with a decimal representation (e.g.: "1.25"). The representation has a decimal point and at least one digit before and after the decimal point. Negative numbers are preceded by a minus sign (e.g.: "-1.25"). The decimal number can have repeating decimals, which are enclosed in parentheses ("e.g.: "0.(3)"). The repeating decimals will not start before the decimal point.

Returns:
the string result of the conversion.

fraction

const func string: fraction (in rational: number)

Convert a rational to a string with a fraction.

fraction(rational("0.(3)"))  returns  "1/3"
Returns:
the string with the corrresponding fraction.

rational

const func rational: rational (in var string: stri)

Convert a string to a rational number. The string must contain a fraction (e.g.: "3/5") or a decimal number (e.g.: "1.25"). In a fraction numerator and denominator are separated with a slash (/). A decimal number can have repeating decimals, which are enclosed in parentheses ("e.g.: "0.(3)"). The repeating decimals are not allowed to start before the decimal point.

rational("3/5")         returns   3 /   5
rational("1.25")        returns   5 /   4
rational("0.(3)")       returns   1 /   3
rational("1.23(45)")    returns 679 / 550
rational("3.(142857)")  returns  22 /   7
rational("0.(846153)")  returns  11 /  13
Returns:
the rational result of the conversion.
Raises:
RANGE_ERROR - If stri contains not a valid rational value.


 previous   up   next