read_exponent {genscore} | R Documentation |
Parses the exponent part into power_numer and power_denom.
Description
Parses the exponent part into power_numer and power_denom.
Usage
read_exponent(s)
Arguments
s |
A string. Must be of the form "" (empty string), "^2", "^(-5/3)" followed by other terms (starting with "+" or "-"). |
Details
Parses the exponential part of the first term into power_numer and power_denom and returns the rest of the terms. Please refer to the examples. s
must be of the form "", "^2", "^(-5/3)" followed by other terms, e.g. "+x2^2", "^2+x2^2", "^(-5/3)+x2^2". Assuming these come from "x1+x2^2", "x1^2+x2^2" and "x1^(-5/3)+x2^2", respectively, these will parsed into power_numer=1, power_denom=1
, power_numer=2, power_denom=1
, and power_numer=-5, power_denom=3
, respectively.
Value
A list containing the following elements:
power_numer |
An integer, the numerator of the power. |
power_denom |
An integer, the denominator of the power. |
s |
A string, the rest of the unparsed string. |
If parsing is unsuccessful, NULL
is returned.
Examples
read_exponent("")
read_exponent("^(-2*4)") # Unsuccessful parsing, returns \code{NULL}.
read_exponent("+x2^(2/3)+x3^(-3/4)") # Comes from "x1+x2^(2/3)+x3^(-3/4)"
read_exponent("^2+x2^(2/3)+x3^(-3/4)") # Comes from "x1^2+x2^(2/3)+x3^(-3/4)"
read_exponent("^(2/3)+x2^(2/3)+x3^(-3/4)") # Comes from "x1^(2/3)+x2^(2/3)+x3^(-3/4)"
read_exponent("^(-2)+x2^(2/3)+x3^(-3/4)") # Comes from "x1^(-2)+x2^(2/3)+x3^(-3/4)"
read_exponent("^(-2/3)+x2^(2/3)+x3^(-3/4)") # Comes from "x1^(-2/3)+x2^(2/3)+x3^(-3/4)"