Introduce new formula: Rational Value (RV). The Rational Value (RV) of a rational literal is an ordered pair consisting of the integers in lowest terms with respect to each other. Below, GreatestCommonDivisor refers to the Greatest Common Divisor algorithm.
No edits are needed for the syntactic grammar, since NonInteger is already there.
Imaginary Numbers
Imaginary numbers have many uses (the term “imaginary” is most unfortunate, since they no more imaginary than “real” numbers), but they’re most commonly recognized as square roots of negative numbers. For example, the square root of −4 is 2i, where i is the unique imaginary number whose square is −1. (Thus 2i 2i = 4i2 = 4 −1 = −4.)
The lexical syntax of an imaginary number is an integer or a float, appended with i.
let a = 6.283_185i;
let b = -2i;
Rational Numbers
Rational numbers are pairs of integers that represent ratios. Rational numbers are multiplied and divided more accurately than floating-point numbers (at the cost of a slight performance hit).
The syntax of a rational number is two integer literals separated by ~, U+007E TILDE, without any whitespace.
let a = -2~10;
let b = 22~7;
let c = \zm~\b111; \ mixing bases is allowed
let c = 3_500~10_000; \ numeric separators are allowed
The only caveat is that the integer literal after~ must be positive (cannot start with - and must contain a non-zero digit). The following are lexical errors: 42~0, 2~-12.
When computed, rational numbers representing equal ratios will be equal.
For example, 1~6 and 2~12 have the same Rational Value (RV).
Tokenize the literal syntaxes for imaginary and rational numbers.
Update Mathematical Value (MV) for imaginary numbers.
Introduce new formula: Rational Value (RV). The Rational Value (RV) of a rational literal is an ordered pair consisting of the integers in lowest terms with respect to each other. Below,
GreatestCommonDivisor
refers to the Greatest Common Divisor algorithm.No edits are needed for the syntactic grammar, since
NonInteger
is already there.Imaginary Numbers
Imaginary numbers have many uses (the term “imaginary” is most unfortunate, since they no more imaginary than “real” numbers), but they’re most commonly recognized as square roots of negative numbers. For example, the square root of −4 is 2i, where i is the unique imaginary number whose square is −1. (Thus 2i 2i = 4i2 = 4 −1 = −4.)
The lexical syntax of an imaginary number is an integer or a float, appended with
i
.Rational Numbers
Rational numbers are pairs of integers that represent ratios. Rational numbers are multiplied and divided more accurately than floating-point numbers (at the cost of a slight performance hit).
The syntax of a rational number is two integer literals separated by
~
, U+007E TILDE, without any whitespace.The only caveat is that the integer literal after
~
must be positive (cannot start with-
and must contain a non-zero digit). The following are lexical errors:42~0
,2~-12
.When computed, rational numbers representing equal ratios will be equal. For example,
1~6
and2~12
have the same Rational Value (RV).