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, is_step_efficiency: false) ⇒ Tonal::Cents
The cents difference between self and its step in the given modulo.
-
#hz ⇒ Tonal::Hertz
(also: #to_hz)
Of self.
-
#interval_with(other_ratio, is_lower: true) ⇒ Tonal::Interval
Beween self (upper) and ratio (lower).
-
#log(base) ⇒ Tonal::Log
(also: #to_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(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Integer?
The maximum prime factor of self, or nil if self has a prime factor above limit.
-
#min_prime(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Integer?
The minimum prime factor of self, or nil if self has a prime factor above limit.
-
#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.
-
#power(p, r = nil) ⇒ Numeric
Self raised to the given power/root.
-
#prime_divisions(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Array?
, self decomposed into its prime factors, or nil if self has a prime factor above limit.
-
#prime_vector(reduced: false, limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Vector
(also: #monzo, #prime_exponent_vector)
, self represented as a prime vector.
-
#reciprocal ⇒ Rational
The reciprocal of self.
-
#root(r) ⇒ Numeric
Self raised to the given root.
-
#scale_step(modulo = 12) ⇒ Tonal::Scale::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_interval ⇒ Tonal::Interval
Between 1/1 (lower) and self (upper).
-
#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.
115 |
# File 'lib/tonal/extensions.rb', line 115 def benedetti_height = ratio.benedetti_height |
#cents ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
83 |
# File 'lib/tonal/extensions.rb', line 83 def cents = Tonal::Cents.new(cents: self) |
#cents_difference_with(other_ratio) ⇒ Tonal::Cents
Returns difference between ratio (upper) and self (lower).
177 |
# File 'lib/tonal/extensions.rb', line 177 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, is_step_efficiency: false) ⇒ Tonal::Cents
Returns the cents difference between self and its step in the given modulo.
154 |
# File 'lib/tonal/extensions.rb', line 154 def efficiency(modulo, reduced: false, is_step_efficiency: false) = ratio(reduced:).efficiency(modulo, is_step_efficiency:) |
#hz ⇒ Tonal::Hertz Also known as: to_hz
Returns of self.
101 |
# File 'lib/tonal/extensions.rb', line 101 def hz = Tonal::Hertz.new(self) |
#interval_with(other_ratio, is_lower: true) ⇒ Tonal::Interval
Returns beween self (upper) and ratio (lower).
164 |
# File 'lib/tonal/extensions.rb', line 164 def interval_with(other_ratio, is_lower: true) = Tonal::Ratio.new(self).interval_with(other_ratio, is_lower:) |
#log(base) ⇒ Tonal::Log Also known as: to_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:) |
#log2 ⇒ Tonal::Log2 Also known as: to_log2, span
Returns the log2 of self.
75 |
# File 'lib/tonal/extensions.rb', line 75 def log2 = Tonal::Log2.new(logarithmand: self) |
#log_floor(base = 10) ⇒ Integer
Returns the floor of the log (to the given base) of self.
235 |
# File 'lib/tonal/extensions.rb', line 235 def log_floor(base=10) = Math.log(self, base).floor |
#log_weil_height ⇒ Tonal::Log2
Returns the log of Weil height.
135 |
# File 'lib/tonal/extensions.rb', line 135 def log_weil_height = ratio.log_weil_height |
#max_prime(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Integer?
Returns the maximum prime factor of self, or nil if self has a prime factor above limit.
201 |
# File 'lib/tonal/extensions.rb', line 201 def max_prime(limit: Tonal::Ratio::PRIME_LIMIT) = ratio.max_prime(limit:) |
#min_prime(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Integer?
Returns the minimum prime factor of self, or nil if self has a prime factor above limit.
208 |
# File 'lib/tonal/extensions.rb', line 208 def min_prime(limit: Tonal::Ratio::PRIME_LIMIT) = ratio.min_prime(limit:) |
#mirror(axis = 1) ⇒ Tonal::Ratio
Returns , the ratio rotated on the given axis, default 1/1.
228 |
# File 'lib/tonal/extensions.rb', line 228 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.
221 |
# File 'lib/tonal/extensions.rb', line 221 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] |
#power(p, r = nil) ⇒ Numeric
Returns self raised to the given power/root.
249 250 251 252 253 254 255 |
# File 'lib/tonal/extensions.rb', line 249 def power(p, r=nil) if r (self.root(r))**p else self**p end end |
#prime_divisions(limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Array?
Returns , self decomposed into its prime factors, or nil if self has a prime factor above limit.
194 |
# File 'lib/tonal/extensions.rb', line 194 def prime_divisions(limit: Tonal::Ratio::PRIME_LIMIT) = ratio.prime_divisions(limit:) |
#prime_vector(reduced: false, limit: Tonal::Ratio::PRIME_LIMIT) ⇒ Vector Also known as: monzo, prime_exponent_vector
Returns , self represented as a prime vector.
185 |
# File 'lib/tonal/extensions.rb', line 185 def prime_vector(reduced: false, limit: Tonal::Ratio::PRIME_LIMIT) = ratio(reduced:).prime_vector(limit:) |
#reciprocal ⇒ Rational
Returns the reciprocal of self.
241 |
# File 'lib/tonal/extensions.rb', line 241 def reciprocal = Rational(1, self) |
#root(r) ⇒ Numeric
Returns self raised to the given root.
262 263 264 |
# File 'lib/tonal/extensions.rb', line 262 def root(r) self**Rational(1, r) end |
#scale_step(modulo = 12) ⇒ Tonal::Scale::Step
Returns the step of self in the given modulo.
109 |
# File 'lib/tonal/extensions.rb', line 109 def scale_step(modulo=12) = Tonal::Scale::Step.new(ratio: self, modulo:) |
#tenney_height ⇒ Integer Also known as: log_product_complexity
Returns the product complexity of self.
122 |
# File 'lib/tonal/extensions.rb', line 122 def tenney_height = ratio.tenney_height |
#to_cents ⇒ Tonal::Cents
Returns of self interpreted as a ratio.
95 |
# File 'lib/tonal/extensions.rb', line 95 def to_cents = Tonal::Cents.new(ratio: self) |
#to_interval ⇒ Tonal::Interval
Returns between 1/1 (lower) and self (upper).
170 |
# File 'lib/tonal/extensions.rb', line 170 def to_interval = Tonal::Interval.new(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:) : Tonal::Ratio.new(self, 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:) |
#to_vector ⇒ Vector Also known as: vector
Returns , self expressed as a Vector.
214 |
# File 'lib/tonal/extensions.rb', line 214 def to_vector = Vector[self.numerator, self.denominator] |
#weil_height ⇒ Integer
Returns the Weil height.
129 |
# File 'lib/tonal/extensions.rb', line 129 def weil_height = ratio.weil_height |
#wilson_height(reduced: false, equave: 2, prime_rejects: [2]) ⇒ Integer
Returns the Wilson height.
143 |
# File 'lib/tonal/extensions.rb', line 143 def wilson_height(reduced: false, equave: 2/1r, prime_rejects: [2]) = ratio(reduced:, equave:).wilson_height(prime_rejects:) |
#¢ ⇒ Tonal::Cents
Returns of self interpreted as a cents quantity.
89 |
# File 'lib/tonal/extensions.rb', line 89 def ¢ = cents |