2 summary:: one-dimensional value
4 related::Classes/Polar, Classes/Complex, Classes/Float, Classes/Integer, Classes/UnaryOpUGen, Classes/BinaryOpUGen
7 Base class for numbers which can be represented by a single one dimensional value.
9 Most of the Unary and Binary operations are also implemented by link::Classes/UnaryOpUGen:: and link::Classes/BinaryOpUGen::, so you can get more examples by looking at the help for those.
14 allocates a new SimpleNumber.
18 private:: prSimpleNumberSeries
20 subsection:: math support
66 Greatest common divisor
69 Round to multiple of aNumber
71 round up to a multiply of aNumber
84 Truncate to multiple of aNumber
87 Arctangent of (this/aNumber)
90 Square root of the sum of the squares.
94 returns:: Base e logarithm.
97 returns:: Base 2 logarithm.
100 returns:: Base 10 logarithm.
106 returns:: absolute value.
109 returns:: Answer -1 if negative, +1 if positive or 0 if zero.
112 returns:: next larger integer.
115 returns:: next smaller integer
148 the square of the number
151 the cube of the number
154 the square root of the number.
157 e to the power of the receiver.
163 this to the power of aNumber
166 the folded value, a bitwise or with aNumber
168 method:: previousPowerOf
169 the number relative to this that is the previous power of aNumber
172 the next power of aNumber
174 method:: nextPowerOfTwo
175 returns:: the number relative to this that is the next power of 2
177 method:: nextPowerOfThree
178 the next power of three
181 returns:: a hash value
184 returns:: the receiver. aNumber is ignored.
195 method:: bitHammingDistance
196 Binary Hamming distance: the count of bits that are not the same in the two numbers
199 returns:: true if bit at index aNumber is set.
202 returns:: ones complement
211 Unsigned binary shift right.
214 returns:: performs a binary right shift
216 method:: unsignedRightShift
217 returns:: performs an unsigned right shift
220 returns:: performs a binary left shift
223 returns:: performs a bitwise or with aNumber
226 returns:: performs a bitwise and with aNumber
256 0 when b <= 0, a*b when b > 0
259 a * b when a < 0, otherwise a.
262 clips receiver to +/- aNumber
265 Returns the difference of the receiver and its clipped form.
273 Answer if the number is >= 0.
276 Answer if the number is < 0.
278 method:: isStrictlyPositive
279 Answer if the number is > 0.
281 method:: booleanValue
282 returns:: true, if strictly positive ( > 0), otherwise false (see link::Classes/Boolean::)
287 subsection:: conversion
290 argument::denominator
291 argument::fasterBetter
292 if true, asFraction may find a much closer approximation and do it faster.
293 returns:: an array of denominator and divisor of the nearest and smallest fraction
295 method:: asAudioRateInput
296 Converts this into an audiorate input.
298 method:: asTimeString
299 Compile a time string.
302 returns:: a string corresponding to the hours:minutes:seconds based on the receiver as number of seconds
307 start = Main.elapsedTime;
308 { loop({(Main.elapsedTime - start).asTimeString.postln; 0.05.wait}) }.fork;
313 returns:: this as link::Classes/Point::. x = y = this.
316 returns:: this as link::Classes/Point::. x = y = this.
319 argument::spec a link::Classes/ControlSpec::
320 returns:: this as link::Classes/CurveWarp:: according to spec.
323 returns:: this as link::Classes/Float::
326 returns:: a link::Classes/Rect:: with x = y = w = h = this.
329 returns:: this as a link::Classes/Boolean::. this > 0
332 returns:: the values as link::Classes/Quant::
335 returns:: this as link::Classes/Integer::
340 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).
343 Create a routine by a function fork
350 "No you didn't".postln;
355 "no you didn't".postln;
363 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).
366 make the current thread sleep, until woken up by re-scheduling. Outside a Routine, this trows an error (see also Routine for details).
368 method:: nextTimeOnGrid
370 returns:: the next possible multiple of the clock's beats.
372 method:: schedBundleArrayOnClock
376 subsection:: series and arrays
378 method:: nearestInList
379 returns:: the value in the list closest to this
384 l = [0, 0.5, 0.9, 1];
385 (0, 0.05..1).collect { |i| i.nearestInList(l) }
389 method:: nearestInScale
391 an array of SimpleNumbers each treated as a step in the octave.
392 argument:: stepsPerOctave
394 returns:: the value in the collection closest to this, assuming an octave repeating table of note values.
399 l = [0, 1, 5, 9, 11]; // pentatonic scale
400 (60, 61..76).collect { |i| i.nearestInScale(l, 12) }
405 return an artithmetic series from this over second to last.
407 This is used in the shortcuts:
412 If second is nil, it is one magnitude step towards last (1 or -1).
421 returns:: a Routine that iterates over the numbers from this to last.
424 Since this is a lazy operation, last may be inf, generating an endless series
425 (see also link::Guides/ListComprehensions::)
427 r = seriesIter(0, 5);
433 subsection:: windowing
436 returns:: a value for a rectangular window function between 0 and 1.
439 returns:: a value for a hanning window function between 0 and 1.
442 returns:: a value for a welsh window function between 0 and 1.
445 returns:: a value for a triangle window function between 0 and 1.
450 a nonlinear distortion function.
453 Distortion with a perfectly linear region from -0.5 to +0.5
456 Map receiver in the onto an S-curve.
459 ((0..100) / 100 ).collect(_.scurve).plot
463 Map receiver onto a ramp starting at 0.
466 ((-100..100) / 100 ).collect(_.ramp).plot
470 returns:: abolute value (see link::Classes/Polar::, link::Classes/Complex::)
473 returns:: angle of receiver conceived as link::Classes/Polar:: or link::Classes/Complex:: number.
478 an array of SimpleNumbers each treated as a step in the octave.
481 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.
485 l = [0, 1, 5, 9, 11]; // pentatonic scale
486 (1, 2..15).collect{|i|
493 inverse of degreeToKey.
495 an array of SimpleNumbers each treated as a step in the octave.
501 l = [0, 1, 5, 9, 11]; // pentatonic scale
502 (60, 61..75).collect { |i| i.keyToDegree(l, 12) }
507 l = [0, 1, 5, 9, 11]; // pentatonic scale
508 (60, 61..75).postln.collect { |i| i.keyToDegree(l, 12).degreeToKey(l) }
515 map the receiver onto a gauss function.
520 a * (exp(squared(this - b) / (-2.0 * squared(c)))) Defalt values: a = 1; b = 0; c = 1
524 (0..1000).normalize(-10, 10).collect { |num| num.gaussCurve }.plot;
528 method:: equalWithPrecision
529 returns:: true if receiver is closer to that than precision.
533 3.1.equalWithPrecision(3.0, 0.05); // false
534 3.1.equalWithPrecision(3.0, 0.1); // false
535 3.1.equalWithPrecision(3.0, 0.11); // true
539 round the receiver to the quantum.
543 Determines how much the value is allowed to differ in the tolerance range.
546 ((0..10) / 10).collect { |num| num.quantize(1, 0.3, 0.5) }.postcs.plot;
547 ((0..10) / 10).collect { |num| num.quantize(1, 0.6, 0.5) }.postcs.plot;
548 ((0..10) / 10).collect { |num| num.quantize(1, 1.0, 0.5) }.postcs.plot;
552 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.
554 assumed input minimum
556 assumed input maximum
565 \minmax (clip both - this is default).
569 (0..10).collect { |num| num.linlin(0, 10, -4.3, 100) };
570 (0..10).linlin(0, 10, -4.3, 100); // equivalent.
574 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.
576 assumed input minimum
578 assumed input maximum
587 \minmax (clip both - this is default).
590 (0..10).collect { |num| num.linexp(0, 10, 4.3, 100) };
591 (0..10).linexp(0, 10, 4.3, 100); // equivalent.
595 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.
596 If the input exceeds the input range, the following behaviours are specified by the clip argument.
598 assumed input minimum
600 assumed input maximum
609 \minmax (clip both - this is default).
612 (1..10).collect { |num| num.explin(0.1, 10, -4.3, 100) };
613 (1..10).explin(0.1, 10, -4.3, 100); // equivalent.
617 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.
618 If the input exceeds the input range, the following behaviours are specified by the clip argument.
620 assumed input minimum
622 assumed input maximum
631 \minmax (clip both - this is default).
634 (1..10).collect { |num| num.expexp(0.1, 10, 4.3, 100) };
635 (1..10).expexp(0.1, 10, 4.3, 100); // equivalent.
639 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.
640 If the input exceeds the input range, the following behaviours are specified by the clip argument.
642 assumed input minimum
644 assumed input maximum
650 0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved)
655 \minmax (clip both - this is default).
658 (0..10).collect { |num| num.lincurve(0, 10, -4.3, 100, -3) };
659 (0..10).lincurve(0, 10, -4.3, 100, -3); // equivalent.
664 (0..100).collect(_.lincurve(0, 100, 0, 1, val)).plot
669 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.
671 assumed input minimum
673 assumed input maximum
679 0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved)
684 \minmax (clip both - this is default).
688 (1..10).collect { |num| num.curvelin(0, 10, -4.3, 100, -3) };
689 (1..10).curvelin(0, 10, -4.3, 100, -3); // equivalent.
694 (0..100).collect(_.curvelin(0, 100, 0, 1, val)).plot
699 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.
702 assumed input minimum
704 assumed input maximum
714 \minmax (clip both - this is default).
717 var center = 0.5, ctlCenter;
718 w = Window("bilin", Rect(100, 100, 200, 100)).front;
719 a = Slider(w, Rect(20, 20, 150, 20)).value_(0.5);
720 b = Slider(w, Rect(20, 45, 150, 20)).value_(0.5);
721 b.action = { center = b.value };
722 a.mouseDownAction = { ctlCenter = a.value };
724 b.value = a.value.bilin(ctlCenter, 0, 1, center, 0, 1);
730 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.
733 assumed input minimum
735 assumed input maximum
745 \minmax (clip both - this is default).
749 // doesn't properly work yet.
751 var center = 0.5, ctlCenter;
752 w = Window("biexp", Rect(100, 100, 200, 100)).front;
753 a = Slider(w, Rect(20, 20, 150, 20)).value_(0.5);
754 b = Slider(w, Rect(20, 45, 150, 20)).value_(0.5);
755 b.action = { center = b.value };
756 a.mouseDownAction = { ctlCenter = a.value + 0.05 };
758 b.value = (a.value + 0.1).biexp(ctlCenter, 0.1, 1.1, center, 0, 1);
764 map the receiver onto an L-curve.
769 a * (m * exp(x) * rTau + 1) / (n * exp(x) * rTau + 1)
771 This is used for smoothing values and limiting them to a range.
773 (0..1000).normalize(-10, 10).collect { |num| num.lcurve }.plot;
778 returns:: converts degree to radian
781 returns:: converts radian to degree
784 Convert MIDI note to cycles per second
785 returns:: cycles per second
788 Convert cycles per second to MIDI note.
793 Convert an interval in semitones to a ratio.
797 Convert a ratio to an interval in semitones.
798 returns:: an interval in semitones
801 Convert a linear amplitude to decibels.
805 Convert a decibels to a linear amplitude.
808 Convert decimal octaves to cycles per second.
811 Convert cycles per second to decimal octaves.
817 stores this on the given stream
819 printrs this on the given stream
824 Answers a Boolean which is the result of a random test whose probability of success in a range from zero to one is this.
827 returns:: Random number from zero up to the receiver, exclusive.
830 returns:: a random number from -this to +this.
833 returns:: a random number in the interval ]a, b[.
837 If both a and b are link::Classes/Integer:: then the result will be an link::Classes/Integer::.
840 returns:: a linearly distributed random number from zero to this.
843 returns:: Bilateral linearly distributed random number from -this to +this.
846 This was suggested by Larry Polansky as a poor man's gaussian.
847 returns:: A random number from -this to +this that is the result of summing three uniform random generators to yield a bell-like distribution.
850 an exponentially distributed random number in the interval ]a, b[. This is always a link::Classes/Float::.
855 a gaussian distributed random number.
859 Always returns a link::Classes/Float::.
861 (0..1000).collect { |num| gauss(0.0, num) }.plot;
865 randomly partition a number into parts of at least min size.
881 method::isValidUGenInput
882 returns:: false if receiver cannot be used in UGen.
883 method:: performBinaryOpOnSignal (aSelector, aSignal)
884 method:: performBinaryOpOnComplex
886 method:: performBinaryOpOnSimpleNumber
888 method:: playAndDelta
890 method:: asBufWithValues