1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
Number : Magnitude {
isNumber { ^true }
+ { arg aNumber; ^this.subclassResponsibility(thisMethod) }
- { arg aNumber; ^this.subclassResponsibility(thisMethod) }
* { arg aNumber; ^this.subclassResponsibility(thisMethod) }
/ { arg aNumber; ^this.subclassResponsibility(thisMethod) }
mod { arg aNumber; ^this.subclassResponsibility(thisMethod) }
div { arg aNumber; ^this.subclassResponsibility(thisMethod) }
pow { arg aNumber; ^this.subclassResponsibility(thisMethod) }
performBinaryOpOnSeqColl { arg aSelector, aSeqColl, adverb;
^aSeqColl.collect({ arg item;
item.perform(aSelector, this, adverb)
})
}
performBinaryOpOnPoint { arg op, aPoint, adverb;
^Point.new(this.perform(op, aPoint.x, adverb), this.perform(op, aPoint.y, adverb));
}
// polar support
rho { ^this }
theta { ^0.0 }
// complex support
real { ^this }
imag { ^0.0 }
// conversion
@ { arg aNumber; ^Point.new(this, aNumber) }
complex { arg imaginaryPart; ^Complex.new(this, imaginaryPart) }
polar { arg angle; ^Polar.new(this, angle) }
// iteration
for { arg endValue, function;
var i, j = 0;
i = this;
while ({ i <= endValue }, { function.value(i, j); i = i + 1; j = j + 1 });
}
forBy { arg endValue, stepValue, function;
var i, j=0;
i = this;
(stepValue > 0).if({
while ({ i <= endValue }, { function.value(i,j); i = i + stepValue; j=j+1; });
}, {
while ({ i >= endValue }, { function.value(i,j); i = i + stepValue; j=j+1; });
});
}
forSeries { arg second, last, function;
// called by generator expression
// compiler replaces this with special byte codes.
var step, j=0;
if (second.isNil) {
last = last ? inf;
step = if (this < last, 1, -1);
}{
last ?? { last = if (second < this, -inf, inf) };
step = second - this;
};
^this.forBy(last, step, function)
}
}
|