Integer:
Filter:
Classes | Math

Integer : SimpleNumber : Number : Magnitude : Object

32-bit Integer number
Source: Integer.sc

Description

A 32-bit integer. Integer inherits most of its behaviour from its superclass, SimpleNumber.

NOTE: Integer can represent values in the range -2147483648 (-2^31) to 2147483647 (2^31 - 1).

The overflow behavior of an Integer is undefined. This occurs whenever the result of an operation does not fit in the range of values supported by the return type, in this case, a 32-bit signed integer. Consider using the 64-bit Float for larger numbers (up to ±2^53).

Class Methods

Inherited class methods

Instance Methods

Iteration

.do(function)

Executes function for all integers from zero to this minus one.

Arguments:

function

a Function which is passed two arguments, both of which are the same integer from zero to this minus one. The reason two arguments are passed is for symmetry with the implementations of do in Collection.

.reverseDo(function)

Executes function for all integers from this minus one to zero.

.for(endval, function)

Executes function for all integers from this to endval, inclusive.

Arguments:

endval

an Integer.

function

a Function which is passed two arguments, the first which is an integer from this to endval, and the second which is a number from zero to the number of iterations minus one.

.forBy(endval, stepval, function)

Executes function for all integers from this to endval, inclusive, stepping each time by stepval.

Arguments:

endval

an Integer.

stepval

an Integer.

function

a Function which is passed two arguments, the first which is an integer from this to endval, and the second which is a number from zero to the number of iterations minus one.

.collect(function)

Returns:

an Array of this size filled by objects generated from evaluating the function.

.collectAs(function, class)

Returns:

a Collection of class of this size filled by objects generated from evaluating the function.

.to(hi, step: 1)

Returns:

an Interval from this to hi.

.geom(start, grow)

Returns:

an array with a geometric series of this size from start.

.fib(a: 0.0, b: 1.0)

Returns:

an array with a fibonacci series of this size beginning with a and b.

.factors

Returns:

the prime factors as array.

Random Numbers

See also: Randomness

.xrand(exclude: 0)

Arguments:

exclude

an Integer.

Returns:

a random value from zero to this, excluding the value exclude.

.xrand2(exclude: 0)

Arguments:

exclude

an Integer.

Returns:

a random value from this.neg to this, excluding the value exclude.

Conversion

.asAscii

Returns:

a Char which has the ASCII value of the receiver.

.asDigit

Returns:

a Char which represents the receiver as an ASCII digit.

Discussion:

For example 5.asDigit returns $5.

.asBinaryDigits(numDigits: 8)

Returns:

an array with the binary digits (integer 0 or 1).

.asDigits(base: 10, numDigits)

Returns:

an array with the n-ary digits.

Discussion:

See also the complementary method SequenceableCollection: -convertDigits.

.asBinaryString(width: 8)

Returns:

a string with the binary digits (0 or 1).

.asHexString(width: 8)

Returns:

a string with the hexadecimal digits (integer 0 to F).

.asIPString

Returns:

a string in IP format.

.asStringToBase(base: 10, width: 8)

Returns:

a string with width-rightmost digits in base base.

Discussion:

.asUnicode

Returns:

the receiver.

.degreeToKey(scale, stepsPerOctave: 12)

Interpret this as index into a scale with a given number of steps per ocatve.

Discussion:

.grayCode

Returns:

the gray code for the number.

Discussion:

.hash

Returns:

a hash value.

Binary Representation

.setBit(bitNumber, bool: true)

set nth bit to zero (bool = false) or one (bool = true)

.leadingZeroes

{ _CLZ }

.trailingZeroes

{ _CTZ }

.numBits

Returns:

number of required bits

Properties

.even

Returns:

true if dividable by 2 with no rest

.odd

Returns:

true if not dividable by 2 with no rest

Powers Of Two

.nextPowerOfTwo

Returns:

the next power of two greater than or equal to the receiver.

Discussion:

.isPowerOfTwo

Returns:

the whether the receiver is a power of two.

Discussion:

Prime Numbers

.nthPrime

Returns:

the nth prime number. The receiver must be from 0 to 6541.

Discussion:

.prevPrime

Returns:

the next prime less than or equal to the receiver up to 65521.

Discussion:

.nextPrime

Returns:

the next prime less than or equal to the receiver up to 65521.

Discussion:

.isPrime

Returns:

whether the receiver is prime.

Discussion:

.indexOfPrime

Returns:

the index of a prime number less than or equal to the receiver up to 65521. If the receiver is not a prime, the answer is nil.

Discussion:

Integer Math

*(aNumber, adverb)

Multiplication.

+(aNumber, adverb)

Addition.

-(aNumber, adverb)

Subtraction.

.modSeaside(aNumber, adverb)

Pre-3.14 modulo with unexpected behavior for negative integer modulus.

For dividends smaller than a negative divisor, modSeaside pulls the resulting remainder below the divisor. It thereby leaves zero as peaks on the zero line. Like in the usual mod, all larger dividends result in remainders above zero.

.clip(lo, hi)

Returns:

  • the receiver if it is between lo and hi
  • lo if the receiver is less than lo
  • hi if the receiver is greater than hi

The result is an Integer only if both lo and hi are Integers.

Discussion:

.factorial

Returns:

the factorial of the receiver as an integer. This will overflow for numbers > 12 and throw an error. Floating point factorials can be used in such cases (see: SimpleNumber: -factorial).

Discussion:

.fold(lo, hi)

Folds in to a value between lo and hi.

Returns:

an Integer between lo and hi.

Discussion:

.log2Ceil

Returns:

next larger integer of the base 2 logarithm of the receiver.

Discussion:

.wrap(lo, hi)

Wraps in to a value between lo and hi.

Returns:

an Integer between lo and hi.

Discussion:

Range Limiting

.clip(lo, hi)

Return this if lo <= this <= hi, otherwise return the nearest boundary: lo if this < lo, hi if this > hi.

Arguments:

lo

The low threshold of clipping.

hi

The high threshold of clipping.

.fold(lo, hi)

Fold this to [lo, hi].

Arguments:

lo

The low threshold of folding.

hi

The high threshold of folding.

.wrap(lo, hi)

Wrap this around [lo, hi] such that it falls in range. Equivalent to (this % (hi - lo + 1)) + lo. Note that this behavior is different from Float: -wrap.

Arguments:

lo

The low threshold (inclusive) of wrapping.

hi

The high threshold (inclusive) of wrapping.

Misc

.exit

Returns:

exits the sclang program and returns the receiver as an exit code to the parent process (e.g. Unix shell).

Discussion:

.generate(function)

Returns:

calls function.value(receiver) but returns the receiver.

Discussion:

.isInteger

Returns:

true (the receiver is an integer).

.isAlt

.isCaps

.isCmd

.isCtrl

.isFun

.isHelp

.isNumPad

.isShift

Returns:

a Boolean for whether or not the given key modifier is in effect. For a list of these, see Modifier Keys.

Discussion:

.pidRunning

Returns:

a Boolean for whether or not the specified pid is running.

Discussion:

Ambisonic Toolkit

.asHoaOrder: METHOD NOT FOUND!

Returns:

a new HoaOrder instance.

.asHoaDegree: METHOD NOT FOUND!

Returns:

a new HoaDegree instance.

Cycle

Browse Math/Cycle

Cycle includes the methods Array: -campanology, Array: -circPerm, Array: -interlace, Array: -kaprekar, Array: -kreuzspiel, Array: -pea, Array: -sieve, Array: -symGroup, Array: -symPerm, Integer: -campanology, Integer: -circPerm, Integer: -collatz, Integer: -discreteLog, Integer: -euclidean, Integer: -kaprekar, Integer: -pea, Number: -lorenz, Env: *collatz.

.campanology: METHOD NOT FOUND!

Apply the method Array: -campanology on positive integers.

Arguments:

mode

assigns the first switched couple as indices either 0 or 1.

rev

Boolean, stops the algorithm when its input is reversed.

sym

Boolean, 'escape from hunt' as a palindromic process for odd number of bells.

Returns:

the cycle itself.

Discussion:

.circPerm: METHOD NOT FOUND!

Arguments:

iBase

in/out base

cBase

circular base

Returns:

the cycle as a circular permutation according to the radix as arguments.

Discussion:

See also Array: -circPerm.

.collatz: METHOD NOT FOUND!

In 1928, Lothar Collatz invented a sequence built from a positive integer according to the following rules:

if x(n) is even, then x(n+1) is equal to x(n) divided by 2;

if x(n) is odd, then x(n+1) is equal to 1 plus x(n) multiplied by 3.

The series thus constructed always ends – until the contrary is proved – by a trivial cycle (4 2 1) for positive integers. This hypothesis is called Syracuse conjecture.

Returns:

the 'path' if it exists until the cycle itself.

Discussion:

Integer: -discreteLog

.discreteLog: METHOD NOT FOUND!

The discrete logarithm forms a cyclic group according to its reciprocal modular exponential defined by g^i mod p.

Arguments:

mod

modulo

Returns:

The cycle itself.

Discussion:

.euclidean: METHOD NOT FOUND!

Application of Bjorklund's algorithm of uniformly distributing some rhythmic impacts in a given interval of rhythmic units – according to Euclid's algorithm determining the greatest common divisor (GCD) [Book VII of the Elements of Euclid].

Reference at http://cgm.cs.mcgill.ca/~godfried/publications/banff.pdf

Arguments:

n

total 'duration' as a number of pulses

ratio

Boolean

Returns:

a binary sequence or an array of relative durations if ratio is set to true.

Discussion:

.kaprekar: METHOD NOT FOUND!

The Kaprekar's algorithm consists to associate any number x to another number K(x) generated as follow:

According to the digits of x in radix n, one forms the number x1 by ranking in increasing order these digits and the number x2 by ranking in decreasing order.

Then K(x) = x2 - x1.

The process is iterated until a cyclic redundancy.

Arguments:

base

Returns:

the cycle itself prepended by its 'path' if it exists.

Discussion:

.pea: METHOD NOT FOUND!

Apply the method Array: -pea to a single positive integer.

Returns:

cycle itself prepended by its 'path' if it exists.

Discussion:

Perfect Powers

.perfectPower: METHOD NOT FOUND!

perfect power decomposition

Returns:

if the receiver can be decomposed into an integer base raised to an integer power, return the base and power as an array, otherwise return nil.

Discussion:

the returned decomposition is in minimal exponent form

.perfectSqrt: METHOD NOT FOUND!

the perfect square root of the number

Returns:

if an integer square root can be found, return, otherwise return nil.

Discussion:

.perfectCbrt: METHOD NOT FOUND!

the perfect cube root of the number

Returns:

if an integer cube root can be found, return, otherwise return nil.

Discussion:

.perfectRootOf: METHOD NOT FOUND!

the perfect root of the number

Returns:

if an integer root can be found, return, otherwise return nil.

Discussion:

.isPerfectPower: METHOD NOT FOUND!

answer if the receiver can be decomposed into an integer base raised to an integer power

Discussion:

observes the convention where the first perfect power is 4

.lcmByGcd: METHOD NOT FOUND!

Calculates the least common multiple by using the greatest common divisor. This can avoid problems with large numbers. See Sieves and Psieve patterns: 4b

Arguments:

... args

Integers

.lcmByFactors: METHOD NOT FOUND!

Calculates the least common multiple by prime factors. This can avoid problems with large numbers. Returns an array with lcm as first item, an array with prime factors of lcm as second item and an array of receiver's and all arguments' prime factors. See Sieves and Psieve patterns: 4b

Arguments:

... args

Integers

Fourier Transform

.fftFreqs: METHOD NOT FOUND!

Returns:

the Discrete Fourier Transform sample frequencies.

Discussion:

.rfftFreqs: METHOD NOT FOUND!

Returns:

the Discrete Fourier Transform sample frequencies.

Discussion:

.dftFreqs: METHOD NOT FOUND!

Returns:

the Discrete Fourier Transform sample frequencies.

Discussion:

Inherited instance methods

Undocumented instance methods

.asBus(rate: 'control', numChannels: 1, server)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asBus.sc

.asGroup

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asGroup.sc

.asNodeID

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asTarget.sc

.asPaddedString(size: 2, padChar: "0", padSide: 'left')

From extension in /usr/local/share/SuperCollider/Extensions/SC3plugins/LoopBufUGens/classes/LJP Classes/Extensions/Integer-asPaddedString.sc

.asTarget

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asTarget.sc

.schedBundle(bundle, server, timeOfRequest)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/schedBundle.sc