Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Libraries AES ARC4 Array ASN.1 Bigfile Bigint Bigrat Bin32 Bin64 Bitdata Bitmapfont Bitset Bitsetof Boolean Browser Bstring Bytedata Cards Category CC config Cgi Cgi dialog Char Charsets Cipher Clib_file Color CLI Commands Complex Console Crc32 Deflate DES Dialog Dir Draw Duration Echo Editline Enable_input Enable_io Enable_output Encoding Environment External_file File File system Float Font Forloop Ftp Getf Gethttp Gethttps Graph Graph_file Gzip Hash Hashsetof Hmac Html_ent Httpserv Idxarray Image Inflate Inflate file Inifile Integer Keybd Line Listener LZW Make Math Msgdigest Null_file Osfiles Picture utility Pixmap_file Pixmapfont PKCS #1 Poll Process Progs Propertyfile Rational Reference Ref_list Scanfile Scanstri Set Shell Smtp Sockbase Socket SQL base Stdio Strifile String Stritext Subrange Tar Text Time TLS/SSL Triple DES Unicode Utf16 Utf8 Vectorfont 3D Vector Wildcard Window Wrinum X.509 Xmldom Xml_ent Zip
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 when 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 var 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
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.
rational
min (in rational: value1, in rational: value2)
Determine the minimum of two rational numbers.
rational
max (in rational: value1, in rational: value2)
Determine the maximum of two rational numbers.
string
str (in rational: number)
Convert a rational number to a string.

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

=

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 preceeded by a minus sign (e.g.: "-1.25"). When 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. When the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - When 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. When the precision is zero the decimal point is omitted.
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - When the precision is negative.

parse

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

Convert a string to a rational number. The string must contain a fraction (e.g.: "3/5"), were numerator and denominator are separated with a slash (/).

Returns:
the rational result of the conversion.
Raises:
RANGE_ERROR - When 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.


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.

min

const func rational: min (in rational: value1, in rational: value2)

Determine the minimum of two rational numbers.

Returns:
the minimum of the two numbers.

max

const func rational: max (in rational: value1, in rational: value2)

Determine the maximum of two rational numbers.

Returns:
the maximum of the two numbers.

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


 previous   up   next