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.
-
#cents_difference_with(other_ratio) ⇒ Tonal::Cents
Difference between ratio (upper) and self (lower).
-
#div_times(factor) ⇒ Array
A tuple of self divided and multiplied by factor.
-
#efficiency(modulo, reduced: false) ⇒ Float
We want the efficiency from the ratio (self).
-
#hz ⇒ Tonal::Hertz
(also: #to_hz)
Of self.
-
#interval_with(other_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::Ratio
, the ratio rotated on the given axis, default 1/1.
-
#modulo_translate(lower = 0, upper) ⇒ Numeric
Translated modularly.
-
#negative ⇒ Tonal::Ratio
, 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(reduced: false) ⇒ Vector
(also: #monzo, #prime_exponent_vector)
, 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: false, equave: 2) ⇒ Tonal::Ratio
(also: #ratio)
The octave reduced ratio of self.
- #to_reduced_ratio(equave: 2) ⇒ Tonal::ReducedRatio
-
#to_vector ⇒ Vector
(also: #vector)
, self expressed as a Vector.
-
#weil_height ⇒ Integer
The Weil height.
-
#wilson_height(reduced: false, 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.
112 |
# File 'lib/tonal/extensions.rb', line 112 def benedetti_height = ratio.benedetti_height |
#cents ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
82 |
# File 'lib/tonal/extensions.rb', line 82 def cents = Tonal::Cents.new(cents: self) |
#cents_difference_with(other_ratio) ⇒ Tonal::Cents
Returns difference between ratio (upper) and self (lower).
163 |
# File 'lib/tonal/extensions.rb', line 163 def cents_difference_with(other_ratio) = interval_with(other_ratio).to_cents |
#div_times(factor) ⇒ Array
Returns a tuple of self divided and multiplied by factor.
40 |
# File 'lib/tonal/extensions.rb', line 40 def div_times(factor) = [self / factor, self * factor] |
#efficiency(modulo, reduced: false) ⇒ Float
We want the efficiency from the ratio (self)
148 |
# File 'lib/tonal/extensions.rb', line 148 def efficiency(modulo, reduced: false) = ratio(reduced: reduced).efficiency(modulo) |
#hz ⇒ Tonal::Hertz Also known as: to_hz
Returns of self.
98 |
# File 'lib/tonal/extensions.rb', line 98 def hz = Tonal::Hertz.new(self) |
#interval_with(other_ratio) ⇒ Tonal::Interval
Returns beween self (upper) and ratio (lower).
155 |
# File 'lib/tonal/extensions.rb', line 155 def interval_with(other_ratio) = Tonal::Interval.new(ratio, other_ratio) |
#log(base) ⇒ Tonal::Log
Returns the log of self to the given base.
68 |
# File 'lib/tonal/extensions.rb', line 68 def log(base) = Tonal::Log.new(logarithmand: self, base: base) |
#log2 ⇒ Tonal::Log2 Also known as: to_log2, span
Returns the log2 of self.
74 |
# File 'lib/tonal/extensions.rb', line 74 def log2 = Tonal::Log2.new(logarithmand: self) |
#log_floor(base = 10) ⇒ Integer
Returns the floor of the log (to the given base) of self.
217 |
# File 'lib/tonal/extensions.rb', line 217 def log_floor(base=10) = Math.log(self, base).floor |
#log_weil_height ⇒ Tonal::Log2
Returns the log of Weil height.
132 |
# File 'lib/tonal/extensions.rb', line 132 def log_weil_height = ratio.log_weil_height |
#max_prime ⇒ Integer
Returns the maximum prime factor of self.
184 |
# File 'lib/tonal/extensions.rb', line 184 def max_prime = prime_divisions.flatten(1).map(&:first).max |
#min_prime ⇒ Integer
Returns the minimum prime factor of self.
190 |
# File 'lib/tonal/extensions.rb', line 190 def min_prime = prime_divisions.flatten(1).map(&:first).min |
#mirror(axis = 1) ⇒ Tonal::Ratio
Returns , the ratio rotated on the given axis, default 1/1.
210 |
# File 'lib/tonal/extensions.rb', line 210 def mirror(axis=1/1r) = ratio.mirror(axis) |
#modulo_translate(lower = 0, upper) ⇒ Numeric
Returns translated modularly.
21 22 23 24 |
# File 'lib/tonal/extensions.rb', line 21 def modulo_translate(lower=0, upper) range = (upper - lower) == 0 ? 1 : upper - lower (self - lower) % range + lower end |
#negative ⇒ Tonal::Ratio
Returns , the Ernst Levy negative of self.
203 |
# File 'lib/tonal/extensions.rb', line 203 def negative = ratio.negative |
#period_degrees ⇒ Float
Returns , the degrees on a circle of self.
62 |
# File 'lib/tonal/extensions.rb', line 62 def period_degrees = ratio.period_degrees |
#plus_minus(offset) ⇒ Array Also known as: min_plus
Returns a tuple of self offset positively/negatively.
32 |
# File 'lib/tonal/extensions.rb', line 32 def plus_minus(offset) = [self + offset, self - offset] |
#prime_divisions ⇒ Array
Returns , self decomposed into its prime factors.
178 |
# File 'lib/tonal/extensions.rb', line 178 def prime_divisions = [self.numerator.prime_division, self.denominator.prime_division] |
#prime_vector(reduced: false) ⇒ Vector Also known as: monzo, prime_exponent_vector
Returns , self represented as a prime vector.
170 |
# File 'lib/tonal/extensions.rb', line 170 def prime_vector(reduced: false) = ratio(reduced: reduced).prime_vector |
#step(modulo = 12) ⇒ Tonal::Step
Returns the step of self in the given modulo.
106 |
# File 'lib/tonal/extensions.rb', line 106 def step(modulo=12) = Tonal::Step.new(ratio: self, modulo: modulo) |
#tenney_height ⇒ Integer Also known as: log_product_complexity
Returns the product complexity of self.
119 |
# File 'lib/tonal/extensions.rb', line 119 def tenney_height = ratio.tenney_height |
#to_cents ⇒ Tonal::Cents
Returns of self interpreted as a ratio.
94 |
# File 'lib/tonal/extensions.rb', line 94 def to_cents = Tonal::Cents.new(ratio: self) |
#to_ratio(reduced: false, equave: 2) ⇒ Tonal::Ratio Also known as: ratio
Returns the octave reduced ratio of self.
48 |
# File 'lib/tonal/extensions.rb', line 48 def to_ratio(reduced: false, equave: 2/1r) = reduced ? Tonal::ReducedRatio.new(self, equave: equave) : Tonal::Ratio.new(self, equave: equave) |
#to_reduced_ratio(equave: 2) ⇒ Tonal::ReducedRatio
56 |
# File 'lib/tonal/extensions.rb', line 56 def to_reduced_ratio(equave: 2/1r) = to_ratio(reduced: true, equave: equave) |
#to_vector ⇒ Vector Also known as: vector
Returns , self expressed as a Vector.
196 |
# File 'lib/tonal/extensions.rb', line 196 def to_vector = Vector[self.numerator, self.denominator] |
#weil_height ⇒ Integer
Returns the Weil height.
126 |
# File 'lib/tonal/extensions.rb', line 126 def weil_height = ratio.weil_height |
#wilson_height(reduced: false, equave: 2, prime_rejects: [2]) ⇒ Integer
Returns the Wilson height.
140 |
# File 'lib/tonal/extensions.rb', line 140 def wilson_height(reduced: false, equave: 2/1r, prime_rejects: [2]) = ratio(reduced: reduced, equave: equave).wilson_height(prime_rejects: prime_rejects) |
#¢ ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
88 |
# File 'lib/tonal/extensions.rb', line 88 def ¢ = cents |