Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/tonal/extensions.rb
Instance Method Summary collapse
-
#benedetti_height ⇒ Float
(also: #product_complexity)
The log product complexity of self.
-
#cents ⇒ Tonal::Cents
Of self interpreted as a cents quantity.
-
#div_times(factor) ⇒ Array
A tuple of self divided and multiplied by factor.
-
#efficiency(modulo) ⇒ Float
The cents difference between self and its step in the given modulo.
-
#hz ⇒ Tonal::Hertz
(also: #to_hz)
Of self.
-
#interval_with(ratio) ⇒ Tonal::Interval
Beween self (upper) and ratio (lower).
-
#log(base) ⇒ Tonal::Log
The log of self to the given base.
-
#log2 ⇒ Tonal::Log2
(also: #to_log2, #span)
The log2 of self.
-
#log_floor(base = 10) ⇒ Integer
The floor of the log (to the given base) of self.
-
#log_weil_height ⇒ Tonal::Log2
The log of Weil height.
-
#max_prime ⇒ Integer
The maximum prime factor of self.
-
#min_prime ⇒ Integer
The minimum prime factor of self.
-
#mirror(axis = 1) ⇒ Tonal::ReducedRatio
, the ratio rotated on the given axis, default 1/1.
-
#modulo_translate(lower = 0, upper) ⇒ Numeric
Translated modularly.
-
#negative ⇒ Tonal::ReducedRatio
, the Ernst Levy negative of self.
-
#period_degrees ⇒ Float
, the degrees on a circle of self.
-
#plus_minus(offset) ⇒ Array
(also: #min_plus)
A tuple of self offset positively/negatively.
-
#prime_divisions ⇒ Array
, self decomposed into its prime factors.
-
#prime_vector ⇒ Vector
(also: #monzo)
, self represented as a prime vector.
-
#step(modulo = 12) ⇒ Tonal::Step
The step of self in the given modulo.
-
#tenney_height ⇒ Integer
(also: #log_product_complexity)
The product complexity of self.
-
#to_cents ⇒ Tonal::Cents
Of self interpreted as a ratio.
-
#to_ratio(reduced: true, equave: 2) ⇒ Tonal::ReducedRatio
(also: #ratio)
The octave reduced ratio of self.
-
#to_vector ⇒ Vector
(also: #vector)
, self expressed as a Vector.
-
#weil_height ⇒ Integer
The Weil height.
-
#wilson_height(reduced: true, equave: 2, prime_rejects: [2]) ⇒ Integer
The Wilson height.
-
#¢ ⇒ Tonal::Cents
Of self interpreted as a cents quantity.
Instance Method Details
#benedetti_height ⇒ Float Also known as: product_complexity
Returns the log product complexity of self.
100 |
# File 'lib/tonal/extensions.rb', line 100 def benedetti_height = self.ratio.benedetti_height |
#cents ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
70 |
# File 'lib/tonal/extensions.rb', line 70 def cents = Tonal::Cents.new(cents: self) |
#div_times(factor) ⇒ Array
Returns a tuple of self divided and multiplied by factor.
37 |
# File 'lib/tonal/extensions.rb', line 37 def div_times(factor) = [self / factor, self * factor] |
#efficiency(modulo) ⇒ Float
Returns the cents difference between self and its step in the given modulo.
132 |
# File 'lib/tonal/extensions.rb', line 132 def efficiency(modulo) = (Tonal::Cents::CENT_SCALE * step(modulo).step / modulo.to_f) - to_cents |
#hz ⇒ Tonal::Hertz Also known as: to_hz
Returns of self.
86 |
# File 'lib/tonal/extensions.rb', line 86 def hz = Tonal::Hertz.new(self) |
#interval_with(ratio) ⇒ Tonal::Interval
Returns beween self (upper) and ratio (lower).
139 |
# File 'lib/tonal/extensions.rb', line 139 def interval_with(ratio) = Tonal::Interval.new(self.ratio, ratio) |
#log(base) ⇒ Tonal::Log
Returns the log of self to the given base.
56 |
# File 'lib/tonal/extensions.rb', line 56 def log(base) = Tonal::Log.new(logarithmand: self, base: base) |
#log2 ⇒ Tonal::Log2 Also known as: to_log2, span
Returns the log2 of self.
62 |
# File 'lib/tonal/extensions.rb', line 62 def log2 = Tonal::Log2.new(logarithmand: self) |
#log_floor(base = 10) ⇒ Integer
Returns the floor of the log (to the given base) of self.
191 |
# File 'lib/tonal/extensions.rb', line 191 def log_floor(base=10) = Math.log(self, base).floor |
#log_weil_height ⇒ Tonal::Log2
Returns the log of Weil height.
120 |
# File 'lib/tonal/extensions.rb', line 120 def log_weil_height = self.ratio.log_weil_height |
#max_prime ⇒ Integer
Returns the maximum prime factor of self.
158 |
# File 'lib/tonal/extensions.rb', line 158 def max_prime = prime_divisions.flatten(1).map(&:first).max |
#min_prime ⇒ Integer
Returns the minimum prime factor of self.
164 |
# File 'lib/tonal/extensions.rb', line 164 def min_prime = prime_divisions.flatten(1).map(&:first).min |
#mirror(axis = 1) ⇒ Tonal::ReducedRatio
Returns , the ratio rotated on the given axis, default 1/1.
184 |
# File 'lib/tonal/extensions.rb', line 184 def mirror(axis=1/1r) = self.ratio.mirror(axis) |
#modulo_translate(lower = 0, upper) ⇒ Numeric
Returns translated modularly.
18 19 20 21 |
# File 'lib/tonal/extensions.rb', line 18 def modulo_translate(lower=0, upper) range = (upper - lower) == 0 ? 1 : upper - lower (self - lower) % range + lower end |
#negative ⇒ Tonal::ReducedRatio
Returns , the Ernst Levy negative of self.
177 |
# File 'lib/tonal/extensions.rb', line 177 def negative = self.ratio.negative |
#period_degrees ⇒ Float
Returns , the degrees on a circle of self.
50 |
# File 'lib/tonal/extensions.rb', line 50 def period_degrees = self.ratio.period_degrees |
#plus_minus(offset) ⇒ Array Also known as: min_plus
Returns a tuple of self offset positively/negatively.
29 |
# File 'lib/tonal/extensions.rb', line 29 def plus_minus(offset) = [self + offset, self - offset] |
#prime_divisions ⇒ Array
Returns , self decomposed into its prime factors.
152 |
# File 'lib/tonal/extensions.rb', line 152 def prime_divisions = [self.numerator.prime_division, self.denominator.prime_division] |
#prime_vector ⇒ Vector Also known as: monzo
Returns , self represented as a prime vector.
145 |
# File 'lib/tonal/extensions.rb', line 145 def prime_vector = self.ratio.prime_vector |
#step(modulo = 12) ⇒ Tonal::Step
Returns the step of self in the given modulo.
94 |
# File 'lib/tonal/extensions.rb', line 94 def step(modulo=12) = to_log2.step(modulo) |
#tenney_height ⇒ Integer Also known as: log_product_complexity
Returns the product complexity of self.
107 |
# File 'lib/tonal/extensions.rb', line 107 def tenney_height = self.ratio.tenney_height |
#to_cents ⇒ Tonal::Cents
Returns of self interpreted as a ratio.
82 |
# File 'lib/tonal/extensions.rb', line 82 def to_cents = self.log2.to_cents |
#to_ratio(reduced: true, equave: 2) ⇒ Tonal::ReducedRatio Also known as: ratio
Returns the octave reduced ratio of self.
43 |
# File 'lib/tonal/extensions.rb', line 43 def to_ratio(reduced: true, equave: 2/1r) = reduced ? Tonal::ReducedRatio.new(self, equave: equave) : Tonal::Ratio.new(self, equave: equave) |
#to_vector ⇒ Vector Also known as: vector
Returns , self expressed as a Vector.
170 |
# File 'lib/tonal/extensions.rb', line 170 def to_vector = Vector[self.numerator, self.denominator] |
#weil_height ⇒ Integer
Returns the Weil height.
114 |
# File 'lib/tonal/extensions.rb', line 114 def weil_height = self.ratio.weil_height |
#wilson_height(reduced: true, equave: 2, prime_rejects: [2]) ⇒ Integer
Returns the Wilson height.
125 |
# File 'lib/tonal/extensions.rb', line 125 def wilson_height(reduced: true, equave: 2/1r, prime_rejects: [2]) = self.ratio(reduced: reduced, equave: equave).wilson_height(prime_rejects: prime_rejects) |
#¢ ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
76 |
# File 'lib/tonal/extensions.rb', line 76 def ¢ = cents |