Operators:

Filter: SuperCollider supports operator overloading. Operators can thus be applied to a variety of different objects; Numbers, Ugens, Collections, and so on. When operators are applied to ugens they result in BinaryOpUGens or UnaryOpUGens, through the methods of AbstractFunction.

This is a list of some of the common unary and binary operators that are implemented by several classes. See the specific classes for details and other operators.

You can see which classes implements a specific operator by clicking on the method name.

Unary operators may be written in two ways:

Inversion.

Reciprocal (1/x).

Absolute value.

Next lower integer.

Next higher integer.

Fractional part.

Sign function.

-1 when a < 0, +1 when a > 0, 0 when a is 0

Squared value.

`a*a`

Cubed value.

`a*a*a`

Square root.

The definition of square root is extended for signals so that sqrt(a) when a<0 returns -sqrt(-a).

Exponential.

Convert MIDI note number to cycles per second.

Convert cycles per second to MIDI note.

Convert an interval in MIDI notes into a frequency ratio.

Convert a frequency ratio to an interval in MIDI notes.

Convert decibels to linear amplitude.

Convert linear amplitude to decibels.

Convert decimal octaves to cycles per second.

Convert cycles per second to decimal octaves.

See also Randomness

Returns an evenly distributed random value between this and zero.

Returns an evenly distributed random value between [+this ... - this].

Returns a linearly distributed random value between this and zero.

Returns a linearly distributed random value between [+this ... - this].

Returns a value from a gaussian-like random distribution between this and zero. This was suggested by Larry Polansky as a loose approximation of gaussian. Follows the formula:

Returns one or zero with the probability given by the argument.

Natural logarithm.

Base 2 logarithm.

Base 10 logarithm.

Sine.

Cosine.

Tangent.

Arcsine.

Arccosine.

Arctangent.

Hyperbolic sine.

Hyperbolic cosine.

Hyperbolic tangent.

Nonlinear distortion.

The formula used is :

Here is an example :

Nonlinear distortion.

Distortion with a perfectly linear region from -0.5 to +0.5

Test if signal is >= 0.

Test if signal is < 0.

Test if signal is > 0.

Three different syntaxes can be used for binary operators consisting of letters:

Operators consisting of symbols are written like this:

Addition.

Subtraction.

Multiplication.

Division.

Floating point modulo.

Exponentiation. Same as pow.

Exponentiation.

NOTE: When used with UGens which produce a negative signal this function extends the usual definition of exponentiation and returns

`neg(neg(a) ** b)`

. This allows exponentiation of negative signal values by noninteger exponents.Least common multiple. This definition extends the usual definition and returns a negative number if **any of the operands** is negative. This makes it consistent with the lattice-theoretical interpretation and its idempotency, commutative, associative, absorption laws.

Following the example of the programming language J (see: J concepts in SC), lcm is analogous to logical **and** (see also: http://www.jsoftware.com/papers/eem/gcd.htm).

Greatest common divisor. This definition extends the usual definition and returns a negative number if **both operands** are negative. This makes it consistent with the lattice-theoretical interpretation and its idempotency, commutative, associative, absorption laws.

"greater" means "divisible by" in this interpretation, so `gcd(-1, -1)`

returns a negative number. This is necessary to make the whole system consistent (fundamental law of arithmetics, idempotency and absorption laws would fail). See examples below.

Following the example of the programming language J (see: J concepts in SC), gcd is analogous to logical **or** (see also: http://www.jsoftware.com/papers/eem/gcd.htm).

Here is an overview of how negative numbers are treated:

Less than.

Less than or equal.

Greater than.

With UGens, this can be useful for triggering purposes, among other things:

Greater than or equal.

Equal.

Not equal.

"Lazy equality." See Object: -|==|.

Return first argument.

Minimum.

Maximum.

Quantization by rounding. Rounds a to the nearest multiple of b.

Quantization by truncation. Truncate a to a multiple of b.

Hypotenuse. Returns the square root of the sum of the squares of a and b. Or equivalently, the distance from the origin to the point (x, y).

In this example, hypot is used to calculate a doppler shift pitch and amplitude based on distance.

The next example uses the distance to modulate a delay line.

Hypotenuse approximation. Returns an approximation of the square root of the sum of the squares of x and y.

The formula used is :

hypotApx is used to implement Complex method magnitudeApx. This should not be used for simulating a doppler shift because it is discontinuous. Use hypot.

Returns the arctangent of y/x.

OK, now we can add a pan to the hypot doppler examples by using atan2 to find the azimuth, or direction angle, of the sound source. Assume speakers at +/- 45 degrees and clip the direction to between those.

Ring modulation plus first source.

Return the value of ((a*b) + a). This is more efficient than using separate unit generators for the multiply and add.

See also *, ring1, ring2, ring3, ring4.

same as :

normal ring modulation:

Ring modulation plus both sources.

Return the value of ((a*b) + a + b). This is more efficient than using separate unit generators for the multiply and adds.

same as :

Ring modulation variant.

Return the value of (a*a *b). This is more efficient than using separate unit generators for each multiply.

same as :

Ring modulation variant.

Return the value of ((a*a *b) - (a*b*b)). This is more efficient than using separate unit generators for each operation.

same as :

Sum of squares.

Return the value of (a*a) + (b*b). This is more efficient than using separate unit generators for each operation.

same as :

Difference of squares.

Return the value of (a*a) - (b*b). This is more efficient than using separate unit generators for each operation.

same as :

Square of the sum.

Return the value of (a + b)**2. This is more efficient than using separate unit generators for each operation.

same as :

Square of the difference.

Return the value of (a - b)**2. This is more efficient than using separate unit generators for each operation.

same as :

Absolute value of the difference. `abs(a - b)`

On a circle, there are two distances between two points. This operator returns the smaller value of the two.

Thresholding.

0 when a < b, otherwise a.

Two quadrant multiply.

0 when b <= 0, a*b when b > 0

Scale negative part of input.

a*b when a < 0, otherwise a.

Bilateral clipping.

clips input wave a to +/- b

Bilateral wrapping.

wraps input wave to +/- b

Bilateral folding.

folds input wave a to +/- b

Residual of clipping.

Returns the difference of the original signal and its clipped form: (a - clip2(a,b)).

helpfile source: /SuperCollider/Contents/Resources/HelpSource/Overviews/Operators.schelp

link::Overviews/Operators::

link::Overviews/Operators::