class Floatboat::Oracle
Constants
- EXPONENT_BIAS
- EXPONENT_BITSIZE
- MANTISSA_BITSIZE
- SIGN_BITSIZE
From IEEE 754 double-precision floats.
Attributes
exponent[R]
mantissa[R]
n_exponent[R]
n_mantissa[R]
n_sign[R]
sign[R]
Public Class Methods
new(f)
click to toggle source
# File lib/floatboat/oracle.rb, line 12 def initialize(f) @value = f bits = ::Floatboat::Converter.to_bits(@value) @sign = bits[0] @exponent = bits[1..11] @mantissa = bits[12..63] @n_sign = @sign == "0" ? 1 : -1 @n_exponent = @exponent.to_i(2) - EXPONENT_BIAS @n_mantissa = ::Floatboat::Converter.binary_mantissa_to_decimal(@mantissa).to_f end
Public Instance Methods
compute_float_value()
click to toggle source
# File lib/floatboat/oracle.rb, line 45 def compute_float_value case @value when Float::INFINITY @value else (@value.nan?) ? Float::NAN : 2**n_exponent * n_mantissa * n_sign end end
to_bit_components()
click to toggle source
# File lib/floatboat/oracle.rb, line 25 def to_bit_components [ sign, exponent, mantissa ] end
to_f()
click to toggle source
# File lib/floatboat/oracle.rb, line 41 def to_f @to_f ||= compute_float_value end
to_numerical_components()
click to toggle source
# File lib/floatboat/oracle.rb, line 33 def to_numerical_components [ n_sign, n_exponent, n_mantissa ] end