Base class for numbers which can be represented by a single one dimensional value.
Most of the Unary and Binary operations are also implemented by UnaryOpUGen and BinaryOpUGen, so you can get more examples by looking at the help for those.
allocates a new SimpleNumber.
Addition
Subtraction
Multiplication
Division
Modulo
Modulo
Integer Division
Exponentiation
Is not
greater than
greater than
greater or equal than
smaller or equal than
Least common multiple
Greatest common divisor
Round to multiple of aNumber
Round up to a multiple of aNumber. For roundDown use trunc.
Truncate to multiple of aNumber (e.g. it rounds numbers down to a multiple of aNumber).
Rounds the value to a multiple of resolution. By using margin and strength you can control which values will be rounded, and by how much.
Conceptually this is the equivalent of MIDI quantization in a DAW/MIDI sequencer. In particular it allows a certain sloppiness close to the resolution value.
Note: this method expects values >= 0.
resolution |
Round this value to a multiple of resolution. E.g. if you chose 1, then all values would be rounded to the nearest integer. |
margin |
Values that are within ±margin from a multiple of resolution will be left as they are. E.g. if you chose a resolution value of 0.5 and a margin of 0.01, then the values 0.501 and 0.499 would be left as they are, but the value 0.502 would become 0.5. This should be a value between 0 and resolution. |
strength |
Determines the degree to which this number will be changed. If strength is 1, then this function will return the nearest resolution. If it is 0, then value of this number will be left unchanged. E.g. If the resolution was 1 and strength was 0.5, then the value 0.6 would become 0.8. |
Rounds the values margin distance from resolution to a multiple of resolution. By using margin and strength you can control when values will be rounded, and by how much.
Conceptually this is the equivalent of 'snap' in a graphics program. Values within a certain distance (margin) from a grid line are snapped to it. All other values are unchanged.
Note: this method expects values >= 0.
resolution |
Snap this value to a multiple of resolution. E.g. if you chose 1, then all values would be rounded to the nearest integer. |
margin |
Only values that are greater ±margin from a multiple of resolution value will be changed. Values that are less than margin will be unchanged. E.g. if you chose a resolution value of 0.5 and a margin of 0.01, then the values 0.501 and 0.499 would be snapped to 0.5, but the value 0.502 would be unchanged. This should be a value between 0 and resolution. |
strength |
Determines the degree to which this number will be changed. If strength is 1, then this function will return the nearest resolution. If it is 0, then value of this number will be left unchanged. E.g. If the resolution was 1 and strength was 0.5, then the value 0.6 would become 0.8. |
Minimum
Maximum
Arctangent of (this/aNumber)
Square root of the sum of the squares.
Base e logarithm.
Base 2 logarithm.
Base 10 logarithm.
negation
absolute value.
Answer -1 if negative, +1 if positive or 0 if zero.
next larger integer.
next smaller integer
Sine
Cosine
Tangent
Arcsine
Arccosine
Arctangent
Hyperbolic sine
Hyperbolic cosine
Hyperbolic tangent
fractional part
the square of the number
the cube of the number
the square root of the number.
e to the power of the receiver.
1 / this
this to the power of aNumber
the folded value, a bitwise or with aNumber
the number relative to this that is the previous power of aNumber
the next power of aNumber
the number relative to this that is the next power of 2
the next power of three
a hash value
the receiver. aNumber is ignored.
Bitwise And
Bitwise Or
Bitwise Exclusive Or
Binary Hamming distance: the count of bits that are not the same in the two numbers
true if bit at index aNumber is set.
ones complement
Binary shift left.
Binary shift right.
Unsigned binary shift right.
performs a binary right shift
performs an unsigned right shift
performs a binary left shift
performs a bitwise or with aNumber
performs a bitwise and with aNumber
(a * b) + a
((a*b) + a + b)
(a * a *b)
((a*a *b) - (a*b*b))
(a*a) - (b*b)
(a*a) + (b*b)
(a - b) ** 2
(a + b) ** 2
(a - b).abs
On a circle, there are two distances between two points. This operator returns the smaller value of the two.
0 when b <= 0, a*b when b > 0
a * b when a < 0, otherwise a.
clips receiver to +/- aNumber
Returns the difference of the receiver and its clipped form.
Answer if the number is >= 0.
Answer if the number is < 0.
Answer if the number is > 0.
true, if strictly positive ( > 0), otherwise false (see Boolean)
denominator | |
fasterBetter |
if true, asFraction may find a much closer approximation and do it faster. |
an array of denominator and divisor of the nearest and smallest fraction
Converts this into an audiorate input.
Produces a time string in the format ddd:hh:mm:ss.sss
, interpreting the receiver as time in seconds. See String: -asSecs for the inverse function.
precision |
accuracy of the millisecond format; the string will always be formatted with 3 decimal places for milliseconds. Minimum value: 0.001. |
maxDays |
maximum number of days |
dropDaysIfPossible |
a Boolean. If set to |
this as Point. x = y = this.
this as Point. x = y = this.
this as Float
a Rect with x = y = w = h = this.
this as a Boolean. this > 0
the values as Quant
this as Integer
within a routine, yield the number so that the clock can wait for this many beats. Outside a Routine, this trows an error (see also Routine for details).
Create a routine by a function fork
like wait, only specify a time (measured in beats of the current thread's clock). Outside a Routine, this trows an error (see also Routine for details).
make the current thread sleep, until woken up by re-scheduling. Outside a Routine, this trows an error (see also Routine for details).
clock |
the next possible multiple of the clock's beats.
the value in the list closest to this
scale |
an array of SimpleNumbers each treated as a step in the octave. |
stepsPerOctave |
12 by default |
the value in the collection closest to this, assuming an octave repeating table of note values.
return an arithmetic series from this over second to last. The last value may not be included in the result if the step size does not divide evenly into the range of the series.
This is used in the shortcuts:
If second is nil, it is one magnitude step towards last (1 or -1). Examples:
a Routine that iterates over the numbers from this to last.
Since this is a lazy operation, last may be inf, generating an endless series (see also List Comprehensions)
a value for a rectangular window function between 0 and 1.
a value for a hanning window function between 0 and 1.
a value for a welsh window function between 0 and 1.
a value for a triangle window function between 0 and 1.
a nonlinear distortion function.
Distortion with a perfectly linear region from -0.5 to +0.5
Map receiver in the onto an S-curve.
Map receiver onto a ramp starting at 0.
scale |
an array of SimpleNumbers each treated as a step in the octave. |
stepsPerOctave |
12 is the standard chromatic scale. |
the value is truncated to an integer and used as an index into an octave repeating table of note values. Indices wrap around the table and shift octaves as they do.
inverse of degreeToKey.
scale |
an array of SimpleNumbers each treated as a step in the octave. |
stepsPerOctave |
12 is the standard chromatic scale. |
map the receiver onto a gauss function.
Uses the formula:
Example code
that |
the number to compare with within precision |
precision |
The absolute precision, independent of the value compared |
relativePrecision |
The precision relative to the larger absolute of the values compared. |
true if receiver is closer to that than precision.
Deprecated. Round the receiver to the quantum. If you're looking for MIDI quantization type features use SimpleNumber#-softRound
quantum |
amount. |
tolerance |
allowed tolerance. |
strength |
Determines how much the value is allowed to differ in the tolerance range. |
map the receiver from an assumed linear input range to a linear output range. If the input exceeds the assumed input range, the behaviour is specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from an assumed linear input range (inMin..inMax) to an exponential output range (outMin..outMax). The output range must not include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from an assumed exponential input range (inMin..inMax) to a linear output range (outMin..outMax). If the input exceeds the assumed input range. The input range must not include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from an assumed exponential input range (inMin..inMax) to an exponential output range (outMin..outMax). If the input exceeds the assumed input range. Both input range and output range must not include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from an assumed linear input range (inMin..inMax) to an exponential curve output range (outMin..outMax). A curve is like the curve parameter in Env. Unlike with linexp, the output range may include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
curve |
0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved) |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from an assumed curve-exponential input range (inMin..inMax) to a linear output range (outMin..outMax). If the input exceeds the assumed input range. A curve is like the curve parameter in Env. Unlike with explin, the input range may include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outMin |
output minimum |
outMax |
output maximum |
curve |
0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved) |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from two assumed linear input ranges (inMin..inCenter) and (inCenter..inMax) to two linear output ranges (outMin..outCenter) and (outCenter..outMax). If the input exceeds the input range, the following behaviours are specified by the clip argument.
inCenter | |
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outCenter | |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver from two assumed exponential input ranges (inMin..inCenter) and (inCenter..inMax) to two linear output ranges (outMin..outCenter) and (outCenter..outMax). The input range must not include zero. If the input exceeds the input range, the following behaviours are specified by the clip argument.
inCenter | |
inMin |
assumed input minimum |
inMax |
assumed input maximum |
outCenter | |
outMin |
output minimum |
outMax |
output maximum |
clip |
nil (don't clip) \max (clip ceiling) \min (clip floor) \minmax (clip both - this is default). |
map the receiver onto an L-curve.
Uses the formula
This is used for smoothing values and limiting them to a range.
converts degree to radian
converts radian to degree
Convert MIDI note to cycles per second
cycles per second
Convert cycles per second to MIDI note.
midi note
Convert an interval in semitones to a ratio.
a ratio
Convert a ratio to an interval in semitones.
an interval in semitones
Convert a linear amplitude to decibels.
Convert a decibels to a linear amplitude.
Convert decimal octaves to cycles per second.
Convert cycles per second to decimal octaves.
stores this on the given stream
prints this on the given stream
Let x be the receiver clipped to the range [0, 1]. With probability x, return true. With probability 1 - x, return false.
Random number from zero up to the receiver, exclusive.
a random number from -this to +this.
aNumber |
the upper limit |
adverb |
a random number in the interval ]a, b[.
If both a and b are Integer then the result will be an Integer.
a linearly distributed random number from zero to this.
Bilateral linearly distributed random number from -this to +this.
This was suggested by Larry Polansky as a loose approximation of gaussian.
A random number from -this to +this that is the result of summing three uniform random generators to yield a bell-like distribution.
an exponentially distributed random number in the interval ]a, b[. This is always a Float. (Note that the distribution of numbers is not exactly an exponential distribution, since that would be unbounded: we might call it a logarithmic uniform distribution.)
aNumber |
the upper limit |
adverb |
a gaussian distributed random number.
standardDeviation |
the upper limit |
Always returns a Float.
randomly partition a number into parts of at least min size.
parts |
number of parts |
min |
the minimum size |
Some methods to ease the development of generic ugen code.
this
false if receiver cannot be used in UGen.
A variety of Special Functions are supplied by the Boost C++ library. The library's online documentation serves as the primary reference for the following functions. The methods here match closely with those found in the source library, as do argument names.
Below you'll find descriptions of the functions and their bounds, but for visualizing the functions, have a look in Tour of Special Functions.
Take a tour of Number Series.
Returns the (2*n
)th Bernoulli number.
Because all odd numbered Bernoulli numbers are zero (apart from B(1) which is -1/2) the interface will only return the even numbered Bernoulli numbers.
Returns a single tangent number at i
. Also called a zag function.
Take a tour of Gamma Functions.
Returns the "true gamma" of value z
.
Returns gamma(dz + 1) - 1
.
Returns the natural logarithm of the gamma function.
Returns the digamma or psi function of z
.
Digamma is defined as the logarithmic derivative of the gamma function.
Returns the trigamma function of z
.
Trigamma is defined as the derivative of the digamma function.
Returns the polygamma function of z
.
Polygamma is defined as the n
'th derivative of the digamma function.
Returns the ratio of gamma functions tgamma(a) / tgamma(b)
.
Returns the ratio of gamma functions tgamma(a) / tgamma(a+delta)
.
Returns the normalised lower incomplete gamma function.
Requires a
> 0 and z
>= 0.
Returns the normalised upper incomplete gamma function.
Requires a
> 0 and z
>= 0.
Returns the full (non-normalised) lower incomplete gamma function.
Requires a
> 0 and z
>= 0.
Returns the full (non-normalised) upper incomplete gamma function.
Requires a
> 0 and z
>= 0.
Returns a value such that p = gamma_p(a, x)
.
Requires a
> 0 and 1 >= p,q
>= 0.
Returns a value x such that q = gamma_q(a, x)
.
Requires a
> 0 and 1 >= p,q
>= 0.
Returns a value such that p = gamma_p(a, x)
.
Requires x
> 0 and 1 >= p,q
>= 0.
Returns a value x such that q = gamma_q(a, x)
.
Requires x
> 0 and 1 >= p,q
>= 0.
Implements the partial derivative with respect to x of the incomplete gamma function (lower).
Implements the partial derivative with respect to x of the incomplete gamma function (upper).
Take a tour of Factorials and Binomial Coefficients.
Returns i!
.
factorial
will overflow if i > 170
Returns i!!
.
For even i
, i !! = i(i-2)(i-4)(i-6) ... (4)(2)
.
For odd i
, i !! = i(i-2)(i-4)(i-6) ... (3)(1)
.
Returns the rising factorial of x
and i
:
x(x+1)(x+2)(x+3)...(x+i-1)
Both x
and i
can be negative as well as positive.
Returns the falling factorial of x
and i
:
x(x-1)(x-2)(x-3)...(x-i+1)
This function is only defined for positive i
. Argument x
can be either positive or negative.
Requires k
<= n
.
Take a tour of Beta Functions.
The beta function is defined by: tgamma(a)*tgamma(b) / tgamma(a+b)
.
Returns the normalised incomplete beta function of a
, b
and x
.
Require 0 <= x
<= 1, a,b
>= 0, and in addition that not both a
and b
are zero.
Returns the normalised complement of the incomplete beta function of a
, b
and x
.
Require 0 <= x
<= 1, a,b
>= 0, and in addition that not both a
and b
are zero.
Returns the full (non-normalised) incomplete beta function of a
, b
and x
.
Require 0 <= x
<= 1, and a,b
> 0.
Returns the full (non-normalised) complement of the incomplete beta function of a
, b
and x
.
Require 0 <= x
<= 1, and a,b
> 0.
Returns a value x
such that: p = ibeta(a, b, x)
.
Requires a,b
> 0 and 0 <= p
<= 1.
Returns a value x
such that: q = ibetaC(a, b, x)
.
Requires a,b
> 0 and 0 <= q
<= 1.
Returns a value a
such that: p = ibeta(a, b, x)
.
Requires b
> 0, 0 < x
< 1, and 0 <= p
<= 1.
Returns a value a
such that: q = ibetaC(a, b, x)
.
Requires b
> 0, 0 < x
< 1, and 0 <= q
<= 1.
Returns a value b
such that: p = ibeta(a, b, x)
.
Requires a
> 0, 0 < x
< 1, and 0 <= p
<= 1.
Returns a value b
such that: q = ibetaC(a, b, x)
.
Requires a
> 0, 0 < x
< 1, and 0 <= q
<= 1.
Returns the partial derivative with respect to x
of the incomplete beta function ibeta(a,b,x)
.
Take a tour of Error Functions.
Returns the error function of z
.
Returns the complement of the error function of z
.
Returns the inverse error function of z
, that is a value x
such that:
p = erf(x)
.
Returns the inverse of the complement of the error function of z
, that is a value x
such that:
p = erfC(x)
Take a tour of Polynomials.
Returns the Legendre Polynomial of the first kind.
Requires -1 <= x
<= 1.
Returns the derivatives of the Legendre polynomials.
Since the Legendre polynomials are alternatively even and odd, only the non-negative zeros are returned. For the odd Legendre polynomials, the first zero is always zero. The rest of the zeros are returned in increasing order.
Returns the associated Legendre polynomial of the first kind.
Requires -1 <= x
<= 1.
Returns the value of the Legendre polynomial that is the second solution to the Legendre differential equation.
Requires -1 <= x
<= 1.
Returns the value of the Laguerre Polynomial of order n
at point x
.
Returns the Associated Laguerre polynomial of degree of dgree n
and order m
at point x
.
Returns the value of the Hermite Polynomial of order n
at point x
.
Returns the Chebyshev polynomials of the first kind.
Returns the Chebyshev polynomials of the second kind.
Returns the derivatives of the Chebyshev polynomials of the first kind.
Returns the roots (zeros) of the n
-th Chebyshev polynomial of the first kind.
Returns the (Complex
) value of the Spherical Harmonic.
theta
is taken as the polar (colatitudinal) coordinate within [0, pi]
, and phi
as the azimuthal (longitudinal) coordinate within [0,2pi]
.
See boost documentation for further information, including a note about the Condon-Shortley phase term of (-1)^m
.
Returns the real part of the Spherical Harmonic.
Returns the imaginary part of the Spherical Harmonic.
Take a tour of Bessel Functions.
Returns the result of the Bessel functions of the first kind.
The functions return the result of domain_error
whenever the result is undefined or complex. This occurs when x < 0
and v
is not an integer, or when x == 0
and v != 0
.
Returns the result of the Bessel functions of the second kind.
The functions return the result of domain_error
whenever the result is undefined or complex. This occurs when x <= 0
.
Returns a single zero or root of the Bessel function of the first kind.
index
is a 1-based index of zero of the cylindrical Bessel function of order v
.
Returns a single zero or root of the Neumann function (Bessel function of the second kind).
index
is a 1-based index of zero of the cylindrical Neumann function of order v
.
Returns the result of the modified Bessel functions of the first kind.
Returns the result of the modified Bessel functions of the second kind.
Requires x > 0
.
Returns the result of the spherical Bessel functions of the first kind.
Requires x
> 0.
Returns the result of the spherical Bessel functions of the first kind.
Requires x
> 0.
Returns the first derivative with respect to x of the corresponding Bessel function.
Returns the first derivative with respect to x of the corresponding Neumann function.
Requires x > 0
.
Returns the first derivative with respect to x of the corresponding Bessel function.
Returns the first derivative with respect to x of the corresponding Bessel function.
Requires x > 0
.
Returns the first derivative with respect to x of the corresponding Bessel function.
Requires x > 0
.
Returns the first derivative with respect to x of the corresponding Neumann function.
Requires x > 0
.
Take a tour of Hankel Functions.
Returns the result of the Hankel functions of the first kind.
Returns the result of the Hankel functions of the second kind.
Returns the result of the spherical Hankel functions of the first kind.
Returns the result of the spherical Hankel functions of the second kind.
Take a tour of Airy Functions.
Returns the result of the Airy function Ai at x
.
Returns the result of the Airy function Bi at x
.
Returns the derivative of the Airy function Ai at x
.
Returns the derivative of the Airy function Bi at x
.
Returns the m
th zero or root of the Airy Ai function. The Airy Ai function has an infinite number of zeros on the negative real axis.
m
is 1-based.
Returns the m
th zero or root (1-based) of the Airy Bi function. The Airy Bi function has an infinite number of zeros on the negative real axis.
m
is 1-based.
Take a tour of Elliptic Integrals.
Returns Carlson's Elliptic Integral RF.
Requires that x,y >= 0
, with at most one of them zero, and that z >= 0
.
Returns Carlson's Elliptic Integral RD.
Requires that x,y >= 0
, with at most one of them zero, and that z >= 0
.
Returns Carlson's Elliptic Integral RJ.
Requires that x,y,z >= 0
, with at most one of them zero, and that p != 0
.
Returns Carlson's Elliptic Integral RC.
Requires that x >= 0
, with at most one of them zero, and that y != 0
.
Returns Carlson's Elliptic Integral RG.
Requires that x,y >= 0
.
Returns the incomplete elliptic integral of the first kind, Legendre form.
Requires -1 <= k <= 1
.
Returns the complete elliptic integral of the first kind, Legendre form.
Requires -1 <= k <= 1
.
Returns the incomplete elliptic integral of the second kind, Legendre form.
Requires -1 <= k <= 1
.
Returns the complete elliptic integral of the second kind, Legendre form.
Requires -1 <= k <= 1
.
Returns the incomplete elliptic integral of the third kind, Legendre form.
Requires -1 <= k <= 1
and n < 1/sin^2(phi)
.
Returns the complete elliptic integral of the third kind, Legendre form.
Requires -1 <= k <= 1
and n < 1
.
Returns the incomplete elliptic integral D(phi, k), Legendre form.
Requires -1 <= k <= 1
.
Returns the complete elliptic integral D(phi, k), Legendre form.
Requires -1 <= k <= 1
.
Returns the result of the Jacobi Zeta Function.
Requires -1 <= k <= 1
.
Returns the result of the Heuman Lambda Function.
Requires -1 <= k <= 1
.
Like all elliptic functions, these can be parameterised in a number of ways:
m
.k
where m = k^2
.α
, where m = sin2α
.This implementation takes the elliptic modulus k
as the parameter. In addition the variable u
is used to express an amplitude φ. All take the elliptic modulus as the first argument - this is for alignment with the Elliptic Integrals.
Take a tour of Jacobi Elliptic Functions.
Take a tour of Zeta Functions.
Returns the zeta function of z
.
Requires z != 1
.
Take a tour of Exponential Integrals.
Returns the exponential integral En of z
.
Requires that when n == 1
, z !=0
.
Returns the exponential integral of z
.
Requires z != 0
.
Take a tour of Basic Functions.
Returns sin(x * π)
.
Returns cos(x * π)
.
Returns the natural logarithm of x+1
.
Returns e^x - 1
.
Returns the cube root of x
.
Returns sqrt(1+x) - 1
.
Returns x^y - 1
.
Take a tour of Sinus Cardinal (Sinc) and Hyperbolic Sinus Cardinal Functions.
Returns the Sinus Cardinal of x
. Also known as the "sinc" function.
sincPi(x) = sin(x) / x
Returns the Hyperbolic Sinus Cardinal of x
.
sinhcPi(x) = sinh(x) / x
Take a tour of Inverse Hyperbolic Functions.
Returns the reciprocal of the hyperbolic sine function at x
.
Returns the reciprocal of the hyperbolic cosine function at x
.
Requires x >= 1
.
Returns the reciprocal of the hyperbolic sine function at x
.
Requires -1 < x < 1
.
Take a tour of Owen's T Function.
Returns the Owens T function of h
and a
.