Mathematical functions, providing stuff that the built-in Math
object doesn't.
- Source:
Members
(static) re_scientificNumber :RegExp
Regex to match numbers in scientific notation.
Type:
- Source:
Methods
(static) abs(n) → {number}
Magnitude of a number - absolute value of a real; modulus of a complex number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) add(a, b) → {number}
Add two numbers.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) addDigits(n, digits) → {string}
Add the given number of zero digits to a string representation of a number.
Parameters:
Name | Type | Description |
---|---|---|
n |
string | A string representation of a number. |
digits |
number | The number of digits to add. |
Returns:
Type | Description |
---|---|
string |
(static) arccos(x) → {number}
Inverse cosine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arccosh(x) → {number}
Inverse hyperbolic cosine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arcsin(x) → {number}
Inverse sine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arcsinh(x) → {number}
Inverse hyperbolic sine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arctan(x) → {number}
Inverse tangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arctanh(x) → {number}
Inverse hyperbolic tangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) arg(n) → {number}
Argument of a (complex) number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) atan2(y, x) → {number}
Angle between x-axis and the line through the origin and (x,y)
.
Parameters:
Name | Type | Description |
---|---|---|
y |
number | |
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) binomialCoefficients(n) → {Array.<number>}
Calculate the Nth row of Pascal's triangle.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
(static) ceil(x) → {number}
Round up to the nearest integer. For complex numbers, real and imaginary parts are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) choose(selection) → {*}
Choose one item from an array, at random.
Parameters:
Name | Type | Description |
---|---|---|
selection |
Array |
Throws:
-
"math.choose.empty selection" if
selection
has length 0. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
* |
(static) combinations(n, k) → {number}
nCk
- number of ways of picking k
unordered elements from n
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
k |
number |
Throws:
-
"math.combinations.complex" if either of
n
ork
is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) complex(re, im) → {complex}
Construct a complex number from real and imaginary parts.
Elsewhere in this documentation, {number}
will refer to either a JavaScript float or a complex
object, interchangeably.
Parameters:
Name | Type | Description |
---|---|---|
re |
number | |
im |
number |
Returns:
Type | Description |
---|---|
complex |
- Source:
(static) complexToString() → {string}
String version of a complex number.
Returns:
Type | Description |
---|---|
string |
- Source:
- See:
(static) conjugate(n) → {number}
Complex conjugate.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) coprime(a, b) → {boolean}
Are a
and b
coprime? If either of a
or b
is not an integer, return false
.
Equivalent to gcd(a,b) = 1
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
boolean |
- Source:
- See:
(static) cos(x) → {number}
Cosine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) cosec(x) → {number}
Cosecant.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) cosech(x) → {number}
Hyperbolic cosecant.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) cosh(x) → {number}
Hyperbolic cosine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) cot(x) → {number}
Cotangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) coth(x) → {number}
Hyperbolic tangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) countDP(n) → {number}
Count the number of decimal places used in the string representation of a number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | string |
Returns:
Type | Description |
---|---|
number |
(static) countSigFigs(n, maxopt) → {number}
Calculate the significant figures precision of a number.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
n |
number | string | if a string, only the "plain" number format or scientific notation is expected. Strings representing numbers should be cleaned first, using |
|
max |
boolean |
<optional> |
Be generous with calculating sig. figs. for whole numbers. e.g. '1000' could be written to 4 sig figs. |
Returns:
Type | Description |
---|---|
number |
(static) deal(N) → {Array.<number>}
Get a random shuffling of the numbers [0..n-1]
.
Parameters:
Name | Type | Description |
---|---|---|
N |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
(static) defineRange(a, b) → {range}
Write the range of integers [a..b]
as an array of the form [min,max,step]
, for use with Numbas.math.random
. If either number is complex, only the real part is used.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
range |
- Source:
- See:
(static) degrees(x) → {number}
Convert from radians to degrees.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
- Source:
- See:
(static) div(a, b) → {number}
Divide one number by another.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) divides(a, b) → {boolean}
Does a
divide b
? If either of a
or b
is not an integer, return false
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
boolean |
(static) divisors(n) → {Array.<number>}
Divisors of n
. When n = 210
, this returns the divisors [1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210]
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
|
(static) eq(a, b) → {boolean}
Is a
equal to b
?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
boolean |
(static) except(range, exclude) → {Array.<number>}
Remove all the values in the list exclude
from the list range
.
Parameters:
Name | Type | Description |
---|---|---|
range |
Array.<number> | |
exclude |
Array.<number> |
Returns:
Type | Description |
---|---|
Array.<number> |
(static) exp(n) → {number}
Calculate e^n
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) factorial(n) → {number}
Factorial, or Gamma(n+1) if n is not a positive integer.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) factorise(n) → {Array.<number>}
Factorise n
. When n=2^(a1)*3^(a2)*5^(a3)*...
, this returns the powers [a1,a2,a3,...]
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
|
(static) floor(x) → {number}
Round down to the nearest integer. For complex numbers, real and imaginary parts are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) fract(x) → {number}
Fractional part of a number - Take away the whole number part. For complex numbers, real and imaginary parts are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
- Source:
- See:
(static) gamma(n) → {number}
Lanczos approximation to the gamma function.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) gcd(a, b) → {number}
Greatest common factor (GCF), or greatest common divisor (GCD), of a
and b
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
"math.gcf.complex" if either of
a
orb
is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) geq(a, b) → {boolean}
Is a
greater than or equal to b
?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
boolean |
(static) gt(a, b) → {boolean}
Is a
greater than b
?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
boolean |
(static) im(n) → {number}
Imaginary part of a number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) integer_partitions(n, k) → {Array.<Array.<number>>}
Produce all of the ordered partitions of the integer n
into k
parts.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
k |
number |
Returns:
Type | Description |
---|---|
Array.<Array.<number>> |
(static) inverse(l) → {Array.<number>}
Calculate the inverse of a shuffling.
Parameters:
Name | Type | Description |
---|---|---|
l |
Array.<number> |
Returns:
Type | Description |
---|---|
Array.<number> |
l |
- Source:
- See:
(static) is_scalar_multiple(u, v, rel_tolopt, abs_tolopt) → {boolean}
Is u
a scalar multiple v
?
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
u |
Array | |||
v |
Array | |||
rel_tol |
number |
<optional> |
1e-15 | Relative tolerance: amount of error relative to |
abs_tol |
number |
<optional> |
1e-15 | Absolute tolerance: maximum absolute difference between |
Returns:
Type | Description |
---|---|
boolean |
(static) isclose(a, b, rel_tolopt, abs_tolopt) → {boolean}
Is a
close to b
?
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
number | |||
b |
number | |||
rel_tol |
number |
<optional> |
1e-15 | Relative tolerance: amount of error relative to |
abs_tol |
number |
<optional> |
1e-15 | Absolute tolerance: maximum absolute difference between |
Returns:
Type | Description |
---|---|
boolean |
(static) largest_square_factor(n) → {number}
The largest perfect square factor of the given number.
When the prime factorisation of n
is p_1^x_1 * p_2^x_2 ... p_k^x_k
, the largest perfect square factor is p_1^(2*floor(x_1/2)) * ... p_k^(2*floor(x_k)/2)
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) lcm(a, b) → {number}
Lowest common multiple (LCM) of a
and b
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
"math.gcf.complex" if either of
a
orb
is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) leq(a, b) → {boolean}
Is a
less than or equal to b
?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
boolean |
(static) listmax(numbers, maxfnopt) → {number}
Greatest of a list of numbers.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
numbers |
Array | |||
maxfn |
function |
<optional> |
Numbas.math.max | A function which returns the maximum of two values. |
Throws:
-
math.order complex numbers
if any element of the list is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) listmin(numbers, minfnopt) → {number}
Least of a list of numbers.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
numbers |
Array | |||
minfn |
function |
<optional> |
Numbas.math.min | A function which returns the minimum of two values. |
Throws:
-
math.order complex numbers
if any element of the list is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) log(n) → {number}
Natural logarithm (base e
).
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) log10(n) → {number}
Base-10 logarithm.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) log_base(n, b) → {number}
Arbitrary base logarithm.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
log(n)/log(b) |
(static) lt(a, b) → {boolean}
Is a
less than b
?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
boolean |
(static) max(a, b) → {number}
Greatest of two numbers - wraps Math.max
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) min(a, b) → {number}
Least of two numbers - wraps Math.min
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
math.order complex numbers
ifa
orb
are complex numbers. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) mod(a, b) → {number}
a mod b
. Always returns a positive number.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) mul(a, b) → {number}
Multiply two numbers.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) negate(n) → {number}
Negate a number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) negative(n) → {boolean}
Is n
negative (Real, and less than 0)?
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
boolean |
(static) neq(a, b) → {boolean}
Are a
and b
unequal?
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
boolean |
- Source:
- See:
(static) niceComplexDecimal(n, options) → {string}
Display a Numbas.math.ComplexDecimal
as a string.
Parameters:
Name | Type | Description |
---|---|---|
n |
Numbas.math.ComplexDecimal | |
options |
Numbas.math.niceNumber_settings |
Returns:
Type | Description |
---|---|
string |
(static) niceDecimal(n, options) → {string}
Display a Decimal as a string.
Parameters:
Name | Type | Description |
---|---|---|
n |
Decimal | |
options |
Numbas.math.niceNumber_settings |
Returns:
Type | Description |
---|---|
string |
(static) niceNumber(n, options) → {string}
Display a number nicely - rounds off to 10dp so floating point errors aren't displayed.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
options |
Numbas.math.niceNumber_settings |
Returns:
Type | Description |
---|---|
string |
(static) niceRealNumber(n, options) → {string}
Display a real number nicely. Unlike Numbas.math.niceNumber
, doesn't deal with complex numbers or multiples of pi.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
options |
Numbas.math.niceNumber_settings |
Returns:
Type | Description |
---|---|
string |
(static) nonnegative(n) → {boolean}
Is n
nonnegative (Real, and greater than or equal to 0)?
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
boolean |
(static) numberToDecimal(x) → {Decimal}
Convert a JS Number to a Decimal.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
Decimal |
(static) parseScientific(str, parseopt) → {object}
Get the significand and exponent of a number written in exponential form.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
str |
string | |||
parse |
boolean |
<optional> |
true | Parse the significand and exponent values to numbers, or leave them as strings? |
Returns:
Type | Description |
---|---|
object |
|
(static) permutations(n, k) → {number}
nPk
- number of ways of picking k
ordered elements from n
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
k |
number |
Throws:
-
"math.combinations.complex" if either of
n
ork
is complex. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) piDegree(n, allowFractionsopt) → {number}
If n
can be written in the form a*pi^n
, with a
an integer, return the biggest possible n
, otherwise return 0
.
Also returns 1
for n
of the form pi/k
, with k
an integer < 1000 if the parameter allowFractions
is true
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n |
number | |||
allowFractions |
boolean |
<optional> |
true | return 1 if |
Returns:
Type | Description |
---|---|
number |
(static) positive(n) → {boolean}
Is n
positive (Real, and greater than 0)?
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
boolean |
(static) pow(a, b) → {number}
Exponentiate a number.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) precround(a, b) → {number}
Round a
to b
decimal places. Real and imaginary parts of complex numbers are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
"math.precround.complex" if b is complex.
- Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) prod(list) → {number}
Multiplies the elements in the given list.
Parameters:
Name | Type | Description |
---|---|---|
list |
Array.<number> |
Returns:
Type | Description |
---|---|
number |
(static) proper_divisors(n) → {Array.<number>}
Proper divisors of n
: the divisors of n
, excluding n
itself. When n = 210
, this returns the divisors [2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105]
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
|
(static) radians(x) → {number}
Convert from degrees to radians.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
- Source:
- See:
(static) random(range) → {number}
Get a random number in the specified range.
Returns a random choice from min
to max
at step
-sized intervals
If all the values in the range are appended to the list, eg [min,max,step,v1,v2,v3,...]
, just pick randomly from the values.
Parameters:
Name | Type | Description |
---|---|---|
range |
range |
|
Returns:
Type | Description |
---|---|
number |
(static) random_integer_partition(n, k) → {Array.<number>}
A random partition of the integer n
into k
non-zero parts.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | |
k |
number |
Returns:
Type | Description |
---|---|
Array.<number> |
|
(static) randomint(n) → {number}
Get a random number in range [0..n-1]
.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) randomrange(min, max) → {number}
Get a random real number between min
and max
(inclusive).
Parameters:
Name | Type | Description |
---|---|---|
min |
number | |
max |
number |
Returns:
Type | Description |
---|---|
number |
(static) rangeSize(range) → {number}
Calculate the number of elements in a range.
Parameters:
Name | Type | Description |
---|---|---|
range |
range |
Returns:
Type | Description |
---|---|
number |
(static) rangeSteps(range, step) → {range}
Change the step size of a range created with Numbas.math.defineRange
.
Parameters:
Name | Type | Description |
---|---|---|
range |
range | |
step |
number |
Returns:
Type | Description |
---|---|
range |
(static) rangeToDecimalList(range) → {Array.<Decimal>}
Convert a range to a list of Decimal values - enumerate all the elements of the range.
Parameters:
Name | Type | Description |
---|---|---|
range |
range |
Returns:
Type | Description |
---|---|
Array.<Decimal> |
(static) rangeToList(range) → {Array.<number>}
Convert a range to a list - enumerate all the elements of the range.
Parameters:
Name | Type | Description |
---|---|---|
range |
range |
Returns:
Type | Description |
---|---|
Array.<number> |
(static) rationalApproximation(n, accuracyopt) → {Array.<number>}
Get a rational approximation to a real number by the continued fractions method.
If accuracy
is given, the returned answer will be within Math.exp(-accuracy)
of the original number.
Based on frap.c by David Eppstein - https://www.ics.uci.edu/~eppstein/numth/frap.c.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
n |
number | ||
accuracy |
number |
<optional> |
Returns:
Type | Description |
---|---|
Array.<number> |
|
(static) re(n) → {number}
Real part of a number.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) reorder(list, order) → {Array}
Reorder a list given a permutation.
The i
th element of the output is the order[i]
th element of list
.
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | The list to reorder. |
order |
Array.<number> | The permutation to apply. |
Returns:
Type | Description |
---|---|
Array |
(static) root(a, b) → {number}
Calculate the b
-th root of a
.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) round(x) → {number}
Round to the nearest integer; fractional part >= 0.5 rounds up. For complex numbers, real and imaginary parts are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) sec(x) → {number}
Secant.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) sech(x) → {number}
Hyperbolic secant.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) shuffle(list) → {Array}
Randomly shuffle a list. Returns a new list - the original is unmodified.
Parameters:
Name | Type | Description |
---|---|---|
list |
Array |
Returns:
Type | Description |
---|---|
Array |
(static) shuffle_together(lists) → {Array.<Array>}
Shuffle a number of lists together - each list has the same permutation of its elements applied. The lists must all be the same length, otherwise an error is thrown.
Parameters:
Name | Type | Description |
---|---|---|
lists |
Array.<Array> | The lists to reorder. |
Returns:
Type | Description |
---|---|
Array.<Array> |
(static) sign(x) → {number}
Sign of a number - +1, 0, or -1. For complex numbers, gives the sign of the real and imaginary parts separately.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) siground(a, b) → {number}
Round a
to b
significant figures. Real and imaginary parts of complex numbers are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Throws:
-
"math.precround.complex" if b is complex.
- Type
- Numbas.Error
Returns:
Type | Description |
---|---|
number |
(static) sin(x) → {number}
Sine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) sinh(x) → {number}
Hyperbolic sine.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) sqrt(n) → {number}
Square root.
Parameters:
Name | Type | Description |
---|---|---|
n |
number |
Returns:
Type | Description |
---|---|
number |
(static) sub(a, b) → {number}
Subtract one number from another.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
Returns:
Type | Description |
---|---|
number |
(static) sum(list) → {number}
Sum the elements in the given list.
Parameters:
Name | Type | Description |
---|---|---|
list |
Array.<number> |
Returns:
Type | Description |
---|---|
number |
(static) tan(x) → {number}
Tangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) tanh(x) → {number}
Hyperbolic tangent.
Parameters:
Name | Type | Description |
---|---|---|
x |
number |
Returns:
Type | Description |
---|---|
number |
(static) toGivenPrecision(n, precisionType, precision, strictPrecision) → {boolean}
Is n given to the desired precision?
Parameters:
Name | Type | Description |
---|---|---|
n |
number | string | |
precisionType |
string | Either 'dp' or 'sigfig'. |
precision |
number | Number of desired digits of precision. |
strictPrecision |
boolean | Must trailing zeros be used to get to the desired precision (true), or is it allowed to give fewer digits in that case (false)? |
Returns:
Type | Description |
---|---|
boolean |
(static) toGivenPrecisionScientific(n, precisionType, precision) → {boolean}
Is n given as a scientific number to the desired precision?
This looks only at the significand part.
A significand of the form D.DD
is considered to be given to 2 decimal places, or three significant figures.
Trailing zeros must be given: 1.2
is only considered to be given to 1 decimal place, and 1.20
is only considered to be given to 2 decimal places.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | string | |
precisionType |
string | Either 'dp' or 'sigfig'. |
precision |
number | Number of desired digits of precision. |
Returns:
Type | Description |
---|---|
boolean |
(static) toNearest(x, a) → {number}
Round to the nearest multiple of a
;For complex numbers, real and imaginary parts are rounded independently.
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
a |
number |
Returns:
Type | Description |
---|---|
number |
- Source:
- See:
(static) trunc(x, popt) → {number}
Integer part of a number - chop off the fractional part. For complex numbers, real and imaginary parts are rounded independently.
When p
is given, truncate to that many decimal places.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number | |||
p |
number |
<optional> |
0 |
Returns:
Type | Description |
---|---|
number |
- Source:
- See:
(static) unscientific(str) → {string}
If the given string is scientific notation representing a number, return a string of the form \d+\.\d+
.
For example, '1.23e-5' is returned as '0.0000123'.
Parameters:
Name | Type | Description |
---|---|---|
str |
string |
Returns:
Type | Description |
---|---|
string |
(static) weighted_random(list) → {*}
Choose at random from a weighted list of items.
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | A list of pairs of the form |
Throws:
-
"math.choose.empty selection" if
selection
has length 0. - Type
- Numbas.Error
Returns:
Type | Description |
---|---|
* |
Type Definitions
niceNumber_settings
Settings for Numbas.math.niceNumber
.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
precisionType |
string | Either |
||
precision |
number | Number of decimal places or significant figures to show. |
||
style |
string | Name of a notational style to use. See |
||
scientificStyle |
string | Name of a notational style to use for the significand in scientific notation. See |
||
syntax |
string | The syntax to use for the rendered string. Either |
||
infinity |
string |
<optional> |
"infinity" | The string to represent infinity. |
imaginary_unit |
string |
<optional> |
"i" | The symbol to represent the imaginary unit. |
circle_constant |
object | An object with attributes |
||
plaindecimal |
boolean | Render |