Enum rcalc_lib::value::Value [−][src]
pub enum Value { Int(BigInt), Float(f64), Ratio(BigRational), Complex(Complex<f64>), }
Expand description
Supported value types (Float is used for angles in degrees)
Variants
Int(BigInt)
Big integer number
Float(f64)
Float number
Ratio(BigRational)
Rational number (numerator and denominator are big integers)
Complex number
Implementations
Convert &str to big integer number Supported formats:
- Raw integer number -
1234
- Integer number and exponent (it must not include decimal point) -
12e2
=1200
- Hexadecimal number -
0x12
or0X12
- Octal number -
0o12
or0O12
- Binary number -
0b101
or0B101
For convenience digits can be separated with underscores:
3_00_1
is the same as 3001
Convert &str to float number Supported formats:
- Without exponent -
1.023
- With exponent -
1.02e-5
Comma(,) can be used instead of decimal point(.):
1.25
is the same as 1,25
For convenience digits can be separated with underscores:
3_005.245_1
is the same as 3005.2451
Convert &str to rational number Supported formats:
- Numerator and denominator only:
1\2
= one half - With integer part:
3\1\2
= three and a half
For convenience digits can be separated with underscores:
3_005\1_988
is the same as 3005\1988
Convert &str that represents angle in degrees to float number Supported formats:
- Full form with letters -
30d20m50s
- 30 degress, 20 angular minutes and 30 angular seconds - Full form with special characters -
30°20'50"
- Short form - degrees only -
30.25d
or30.25°
Characters can be mixed: 30d20'50"
. Letters can be either lowercase or capital ones.
Comma(,) can be used instead of decimal point(.):
1.25d
is the same as 1,25d
For convenience digits can be separated with underscores:
3_005.245_1d
is the same as 3005.2451d
Convert &str to complex number Supported formats:
- “post” marker -
1+2i
- *pre“ marker -
1+i2
i
can be capital one. Instead of i
letter j
can be used.
Note: while omitting real part is supported by this converter(e.g,
it parses 2i
to 0+2i
), it is discouraged. Because a parser that
parses the entire expression cannot detect such cases and may generate
an error.
Comma(,) can be used instead of decimal point(.):
1.25d
is the same as 1,25d
For convenience digits can be separated with underscores:
3_005.245_1d
is the same as 3005.2451d
Returns true if the value is zero or greater
Divides and truncates the result. Note: the result is always big integer number even if two complex numbers are divided. It means in that the result for complex numbers may be incorrect or strange
Inverts the sign of the value
Calculates modulus of a complex number
Conjugates a complex number
Returns imaginary part of a complex number
Returns real part of a complex number
Inverts value as if it is a boolean one. Since the library does not have dedicated type for boolean values, big integers play their role. Rules of inversion:
- Any zero value ->
1
0
in all other cases
Extract fractional part of a float number
Returns absolute value of a number For complex numbers only its real part changes
Squares the value. Automatically converts complex number into float one if imaginary part of the result is zero
Returns sign of the number (for complex number it is a sign of real part):
1
for a number greater than0
0
for zero number-1
for number less than0
Returns square root of a number. Automatically converts a negative number into complex one before calculation
Returns cubic root of a number.
Raises a number into arbitrary power.
Automatic conversion as sqrt
does is not not supported yet.
For integer power degrees the fast and accurate algorithm is used.
For float degrees the power is calculated using exp
Returns factorial of a number. Complex numbers generates an error. Calculation factorial of negative or float number using gamma function is not supported yet
Returns natural logarithm of a number. Automatically converts a negative number to a complex one before calculation
Converts float or integer number into rational one. Complex numbers generate an error
Greatest common divisor
Least Common Multiple
Is Value a prime number. Returns error if a value is not integer Naive and slow algorithm for large integers
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Value
impl UnwindSafe for Value
Blanket Implementations
Mutably borrows from an owned value. Read more