class Numeric

The base class of all numbers, i.e. integers and floats

Public Instance Methods

as_units(units) click to toggle source
# File lib/origen/core_ext/numeric.rb, line 56
def as_units(units)
  if abs >= 1_000_000_000_000_000
    "#{self / 1_000_000_000_000_000.0}P#{units}"
  elsif abs >= 1_000_000_000_000
    "#{self / 1_000_000_000_000.0}T#{units}"
  elsif abs >= 1_000_000_000
    "#{self / 1_000_000_000.0}G#{units}"
  elsif abs >= 1_000_000
    "#{self / 1_000_000.0}M#{units}"
  elsif abs >= 1_000
    "#{self / 1_000.0}k#{units}"
  elsif abs >= 1
    "#{self}#{units}"
  elsif abs >= 1e-3
    "#{self * 1_000}m#{units}"
  elsif abs >= 1e-6
    "#{self * 1_000_000}u#{units}"
  elsif abs >= 1e-9
    "#{self * 1_000_000_000}n#{units}"
  elsif abs >= 1e-12
    "#{self * 1_000_000_000_000}p#{units}"
  elsif abs >= 1e-15
    "#{self * 1_000_000_000_000_000}a#{units}"
  else
    "%.3e#{units}" % self
  end
end
hi_z?() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 10
def hi_z?;
  false;
end
ms!() click to toggle source

Shorthand for tester.wait(time_in_ms: 100), e.g. 100.ms!

# File lib/origen/core_ext/numeric.rb, line 202
def ms!
  Origen.app.tester.wait time_in_ms: self
end
ns!() click to toggle source

Shorthand for tester.wait(time_in_ns: 100), e.g. 100.ns!

# File lib/origen/core_ext/numeric.rb, line 192
def ns!
  Origen.app.tester.wait time_in_ns: self
end
reverse_bits(width) click to toggle source

Reverses the bit representation of a number and returns the new value. Useful when changing register data based on bit order

# File lib/origen/core_ext/numeric.rb, line 48
def reverse_bits(width)
  result = 0
  0.upto(width - 1) do |i|
    result += self[i] * 2**(width - 1 - i)
  end
  result
end
s!() click to toggle source

Shorthand for tester.wait(time_in_s: 100), e.g. 100.s!

# File lib/origen/core_ext/numeric.rb, line 207
def s!
  Origen.app.tester.wait time_in_s: self
end
to_bin() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 34
def to_bin
  "0b#{to_s(2)}"
end
to_bitstring(width) click to toggle source

Converts a number to a String representing binary number Requires width of bit string for padding. If the width is less than the number of bits required to represent the number the width argument is meaningless.

# File lib/origen/core_ext/numeric.rb, line 42
def to_bitstring(width)
  '%0*b' % [width, self]
end
to_hex() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 30
def to_hex
  "0x#{to_s(16).upcase}"
end
undefined?() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 18
def undefined?;
  false;
end
us!() click to toggle source

Shorthand for tester.wait(time_in_us: 100), e.g. 100.us!

# File lib/origen/core_ext/numeric.rb, line 197
def us!
  Origen.app.tester.wait time_in_us: self
end
x?() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 14
def x?;
  false;
end
x_or_z?() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 22
def x_or_z?;
  false;
end
z?() click to toggle source

Helpers for cases where a method may return a 0, 1 or an instance of Origen::Value::X or Origen::Value::Z

# File lib/origen/core_ext/numeric.rb, line 6
def z?;
  false;
end
z_or_x?() click to toggle source
# File lib/origen/core_ext/numeric.rb, line 26
def z_or_x?;
  false;
end