Module: VectorNumber::Querying
- Included in:
- VectorNumber
- Defined in:
- lib/vector_number/querying.rb
Overview
Methods for querying state of the number. Mostly modeled after Complex.
Instance Method Summary collapse
-
#finite? ⇒ Boolean
Returns
true
if all coefficients are finite,false
otherwise. -
#infinite? ⇒ 1?
Returns
1
if any coefficients are infinite,nil
otherwise. -
#integer? ⇒ false
Always returns
false
, as vectors are not Integers. -
#negative? ⇒ Boolean
Returns
true
if number is non-zero and all non-zero coefficients are negative, andfalse
otherwise. -
#nonnumeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber contains any non-numeric parts.
-
#nonzero? ⇒ VectorNumber?
Returns
self
if there are any non-zero coefficients,nil
otherwise. -
#numeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber can be considered strictly numeric, e.g.
-
#positive? ⇒ Boolean
Returns
true
if number is non-zero and all non-zero coefficients are positive, andfalse
otherwise. -
#real? ⇒ false
Always returns
false
, as vectors are not real numbers. -
#zero? ⇒ Boolean
Returns
true
if there are no non-zero coefficients, andfalse
otherwise.
Instance Method Details
#finite? ⇒ Boolean
Returns true
if all coefficients are finite, false
otherwise.
54 55 56 |
# File 'lib/vector_number/querying.rb', line 54 def finite? all? { |_u, v| v.finite? } end |
#infinite? ⇒ 1?
Returns 1
if any coefficients are infinite, nil
otherwise.
This behavior is the same as Complex
‘s.
70 71 72 |
# File 'lib/vector_number/querying.rb', line 70 def infinite? finite? ? nil : 1 # rubocop:disable Style/ReturnNilInPredicateMethodDefinition end |
#integer? ⇒ false
Always returns false
, as vectors are not Integers.
148 |
# File 'lib/vector_number/querying.rb', line 148 def integer? = false |
#negative? ⇒ Boolean
Returns true
if number is non-zero and all non-zero coefficients are negative, and false
otherwise.
128 129 130 |
# File 'lib/vector_number/querying.rb', line 128 def negative? !zero? && all? { |_u, c| c.negative? } end |
#nonnumeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber contains any non-numeric parts.
42 |
# File 'lib/vector_number/querying.rb', line 42 def nonnumeric?(dimensions = 2) = !numeric?(dimensions) |
#nonzero? ⇒ VectorNumber?
Returns self
if there are any non-zero coefficients, nil
otherwise.
This behavior is the same as Numeric
‘s.
96 97 98 |
# File 'lib/vector_number/querying.rb', line 96 def nonzero? zero? ? nil : self # rubocop:disable Style/ReturnNilInPredicateMethodDefinition end |
#numeric?(dimensions = 2) ⇒ Boolean
Whether this VectorNumber can be considered strictly numeric, e.g. real or complex.
23 24 25 26 27 |
# File 'lib/vector_number/querying.rb', line 23 def numeric?(dimensions = 2) raise ArgumentError, "`dimensions` must be non-negative" unless dimensions >= 0 size <= dimensions && (1..dimensions).count { @data[UNIT[_1]].nonzero? } == size end |
#positive? ⇒ Boolean
Returns true
if number is non-zero and all non-zero coefficients are positive, and false
otherwise.
112 113 114 |
# File 'lib/vector_number/querying.rb', line 112 def positive? !zero? && all? { |_u, c| c.positive? } end |
#real? ⇒ false
Always returns false
, as vectors are not real numbers.
This behavior is the same as Complex
‘s.
141 |
# File 'lib/vector_number/querying.rb', line 141 def real? = false |
#zero? ⇒ Boolean
Returns true
if there are no non-zero coefficients, and false
otherwise.
83 |
# File 'lib/vector_number/querying.rb', line 83 def zero? = size.zero? |