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.
278 Answer if the number is >= 0.
281 Answer if the number is < 0.
283 method:: isStrictlyPositive
284 Answer if the number is > 0.
286 method:: booleanValue
287 returns:: true, if strictly positive ( > 0), otherwise false (see link::Classes/Boolean::)
292 subsection:: conversion
295 argument::denominator
296 argument::fasterBetter
297 if true, asFraction may find a much closer approximation and do it faster.
298 returns:: an array of denominator and divisor of the nearest and smallest fraction
300 method:: asAudioRateInput
301 Converts this into an audiorate input.
303 method:: asTimeString
304 Compile a time string.
308 the maximum number of days
309 argument::dropDaysIfPossible
310 a link::Classes/Boolean::
311 returns:: a string corresponding to the hours:minutes:seconds based on the receiver as number of seconds
316 start = Main.elapsedTime;
317 { loop({(Main.elapsedTime - start).asTimeString.postln; 0.05.wait}) }.fork;
322 returns:: this as link::Classes/Point::. x = y = this.
325 returns:: this as link::Classes/Point::. x = y = this.
329 a link::Classes/ControlSpec::
330 returns:: this as link::Classes/CurveWarp:: according to spec.
333 returns:: this as link::Classes/Float::
336 returns:: a link::Classes/Rect:: with x = y = w = h = this.
339 returns:: this as a link::Classes/Boolean::. this > 0
342 returns:: the values as link::Classes/Quant::
345 returns:: this as link::Classes/Integer::
350 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).
353 Create a routine by a function fork
360 "No you didn't".postln;
365 "no you didn't".postln;
373 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).
376 make the current thread sleep, until woken up by re-scheduling. Outside a Routine, this trows an error (see also Routine for details).
378 method:: nextTimeOnGrid
380 returns:: the next possible multiple of the clock's beats.
382 method:: schedBundleArrayOnClock
386 subsection:: series and arrays
388 method:: nearestInList
389 returns:: the value in the list closest to this
394 l = [0, 0.5, 0.9, 1];
395 (0, 0.05..1).collect { |i| i.nearestInList(l) }
399 method:: nearestInScale
401 an array of SimpleNumbers each treated as a step in the octave.
402 argument:: stepsPerOctave
404 returns:: the value in the collection closest to this, assuming an octave repeating table of note values.
409 l = [0, 1, 5, 9, 11]; // pentatonic scale
410 (60, 61..76).collect { |i| i.nearestInScale(l, 12) }
415 return an artithmetic series from this over second to last.
417 This is used in the shortcuts:
422 If second is nil, it is one magnitude step towards last (1 or -1).
431 returns:: a Routine that iterates over the numbers from this to last.
434 Since this is a lazy operation, last may be inf, generating an endless series
435 (see also link::Guides/ListComprehensions::)
437 r = seriesIter(0, 5);
443 subsection:: windowing
446 returns:: a value for a rectangular window function between 0 and 1.
449 returns:: a value for a hanning window function between 0 and 1.
452 returns:: a value for a welsh window function between 0 and 1.
455 returns:: a value for a triangle window function between 0 and 1.
460 a nonlinear distortion function.
463 Distortion with a perfectly linear region from -0.5 to +0.5
466 Map receiver in the onto an S-curve.
469 ((0..100) / 100 ).collect(_.scurve).plot
473 Map receiver onto a ramp starting at 0.
476 ((-100..100) / 100 ).collect(_.ramp).plot
480 returns:: abolute value (see link::Classes/Polar::, link::Classes/Complex::)
483 returns:: angle of receiver conceived as link::Classes/Polar:: or link::Classes/Complex:: number.
488 an array of SimpleNumbers each treated as a step in the octave.
489 argument:: stepsPerOctave
490 12 is the standard chromatic scale.
492 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.
496 l = [0, 1, 5, 9, 11]; // pentatonic scale
497 (1, 2..15).collect{|i|
504 inverse of degreeToKey.
506 an array of SimpleNumbers each treated as a step in the octave.
507 argument:: stepsPerOctave
508 12 is the standard chromatic scale.
512 l = [0, 1, 5, 9, 11]; // pentatonic scale
513 (60, 61..75).collect { |i| i.keyToDegree(l, 12) }
518 l = [0, 1, 5, 9, 11]; // pentatonic scale
519 (60, 61..75).postln.collect { |i| i.keyToDegree(l, 12).degreeToKey(l) }
526 map the receiver onto a gauss function.
531 a * (exp(squared(this - b) / (-2.0 * squared(c)))) Defalt values: a = 1; b = 0; c = 1
535 (0..1000).normalize(-10, 10).collect { |num| num.gaussCurve }.plot;
539 method:: equalWithPrecision
540 returns:: true if receiver is closer to that than precision.
544 3.1.equalWithPrecision(3.0, 0.05); // false
545 3.1.equalWithPrecision(3.0, 0.1); // false
546 3.1.equalWithPrecision(3.0, 0.11); // true
550 round the receiver to the quantum.
556 Determines how much the value is allowed to differ in the tolerance range.
559 ((0..10) / 10).collect { |num| num.quantize(1, 0.3, 0.5) }.postcs.plot;
560 ((0..10) / 10).collect { |num| num.quantize(1, 0.6, 0.5) }.postcs.plot;
561 ((0..10) / 10).collect { |num| num.quantize(1, 1.0, 0.5) }.postcs.plot;
565 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.
567 assumed input minimum
569 assumed input maximum
578 \minmax (clip both - this is default).
582 (0..10).collect { |num| num.linlin(0, 10, -4.3, 100) };
583 (0..10).linlin(0, 10, -4.3, 100); // equivalent.
587 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.
589 assumed input minimum
591 assumed input maximum
600 \minmax (clip both - this is default).
603 (0..10).collect { |num| num.linexp(0, 10, 4.3, 100) };
604 (0..10).linexp(0, 10, 4.3, 100); // equivalent.
608 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.
609 If the input exceeds the input range, the following behaviours are specified by the clip argument.
611 assumed input minimum
613 assumed input maximum
622 \minmax (clip both - this is default).
625 (1..10).collect { |num| num.explin(0.1, 10, -4.3, 100) };
626 (1..10).explin(0.1, 10, -4.3, 100); // equivalent.
630 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.
631 If the input exceeds the input range, the following behaviours are specified by the clip argument.
633 assumed input minimum
635 assumed input maximum
644 \minmax (clip both - this is default).
647 (1..10).collect { |num| num.expexp(0.1, 10, 4.3, 100) };
648 (1..10).expexp(0.1, 10, 4.3, 100); // equivalent.
652 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.
653 If the input exceeds the input range, the following behaviours are specified by the clip argument.
655 assumed input minimum
657 assumed input maximum
663 0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved)
668 \minmax (clip both - this is default).
671 (0..10).collect { |num| num.lincurve(0, 10, -4.3, 100, -3) };
672 (0..10).lincurve(0, 10, -4.3, 100, -3); // equivalent.
677 (0..100).collect(_.lincurve(0, 100, 0, 1, val)).plot
682 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.
684 assumed input minimum
686 assumed input maximum
692 0 (linear) <0 (concave, negatively curved) >0 (convex, positively curved)
697 \minmax (clip both - this is default).
701 (1..10).collect { |num| num.curvelin(0, 10, -4.3, 100, -3) };
702 (1..10).curvelin(0, 10, -4.3, 100, -3); // equivalent.
707 (0..100).collect(_.curvelin(0, 100, 0, 1, val)).plot
712 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.
715 assumed input minimum
717 assumed input maximum
727 \minmax (clip both - this is default).
730 var center = 0.5, ctlCenter;
731 w = Window("bilin", Rect(100, 100, 200, 100)).front;
732 a = Slider(w, Rect(20, 20, 150, 20)).value_(0.5);
733 b = Slider(w, Rect(20, 45, 150, 20)).value_(0.5);
734 b.action = { center = b.value };
735 a.mouseDownAction = { ctlCenter = a.value };
737 b.value = a.value.bilin(ctlCenter, 0, 1, center, 0, 1);
743 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.
746 assumed input minimum
748 assumed input maximum
758 \minmax (clip both - this is default).
762 // doesn't properly work yet.
764 var center = 0.5, ctlCenter;
765 w = Window("biexp", Rect(100, 100, 200, 100)).front;
766 a = Slider(w, Rect(20, 20, 150, 20)).value_(0.5);
767 b = Slider(w, Rect(20, 45, 150, 20)).value_(0.5);
768 b.action = { center = b.value };
769 a.mouseDownAction = { ctlCenter = a.value + 0.05 };
771 b.value = (a.value + 0.1).biexp(ctlCenter, 0.1, 1.1, center, 0, 1);
777 map the receiver onto an L-curve.
782 a * (m * exp(x) * rTau + 1) / (n * exp(x) * rTau + 1)
784 This is used for smoothing values and limiting them to a range.
786 (0..1000).normalize(-10, 10).collect { |num| num.lcurve }.plot;
791 returns:: converts degree to radian
794 returns:: converts radian to degree
797 Convert MIDI note to cycles per second
798 returns:: cycles per second
801 Convert cycles per second to MIDI note.
806 Convert an interval in semitones to a ratio.
810 Convert a ratio to an interval in semitones.
811 returns:: an interval in semitones
814 Convert a linear amplitude to decibels.
818 Convert a decibels to a linear amplitude.
821 Convert decimal octaves to cycles per second.
824 Convert cycles per second to decimal octaves.
830 stores this on the given stream
832 printrs this on the given stream
837 Answers a Boolean which is the result of a random test whose probability of success in a range from zero to one is this.
840 returns:: Random number from zero up to the receiver, exclusive.
843 returns:: a random number from -this to +this.
849 returns:: a random number in the interval ]a, b[.
851 If both a and b are link::Classes/Integer:: then the result will be an link::Classes/Integer::.
854 returns:: a linearly distributed random number from zero to this.
857 returns:: Bilateral linearly distributed random number from -this to +this.
860 This was suggested by Larry Polansky as a poor man's gaussian.
861 returns:: A random number from -this to +this that is the result of summing three uniform random generators to yield a bell-like distribution.
864 an exponentially distributed random number in the interval ]a, b[. This is always a link::Classes/Float::.
870 a gaussian distributed random number.
871 argument::standardDeviation
874 Always returns a link::Classes/Float::.
876 (0..1000).collect { |num| gauss(0.0, num) }.plot;
880 randomly partition a number into parts of at least min size.
893 subsection:: UGen Compatibility Methods
895 Some methods to ease the development of generic ugen code.
897 method:: lag, lag2, lag3, lagud, lag2ud, lag3ud, slew, varlag
899 returns:: code::this::
904 method:: isValidUGenInput
905 returns:: false if receiver cannot be used in UGen.