class Numeric
The base class of all numbers, i.e. integers and floats
Public Instance Methods
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
Source
# File lib/origen/core_ext/numeric.rb, line 202 def ms! Origen.app.tester.wait time_in_ms: self end
Shorthand for tester.wait(time_in_ms: 100), e.g. 100.ms!
Source
# File lib/origen/core_ext/numeric.rb, line 192 def ns! Origen.app.tester.wait time_in_ns: self end
Shorthand for tester.wait(time_in_ns: 100), e.g. 100.ns!
Source
# 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
Reverses the bit representation of a number and returns the new value. Useful when changing register data based on bit order
Source
# File lib/origen/core_ext/numeric.rb, line 207 def s! Origen.app.tester.wait time_in_s: self end
Shorthand for tester.wait(time_in_s: 100), e.g. 100.s!
Source
# File lib/origen/core_ext/numeric.rb, line 42 def to_bitstring(width) '%0*b' % [width, self] end
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.
Source
# File lib/origen/core_ext/numeric.rb, line 30 def to_hex "0x#{to_s(16).upcase}" end
Source
# File lib/origen/core_ext/numeric.rb, line 197 def us! Origen.app.tester.wait time_in_us: self end
Shorthand for tester.wait(time_in_us: 100), e.g. 100.us!
Source
# File lib/origen/core_ext/numeric.rb, line 6 def z?; false; end
Helpers for cases where a method may return a 0, 1 or an instance of Origen::Value::X
or Origen::Value::Z