Class: Float
Overview
Float constants.
Note that this uses the “fractional significand” interpretation, i.e. the significand has the radix point before its first digit.
Float::RADIX : b = Radix of exponent representation,2
Float::MANT_DIG : p = bits (base-RADIX digits) in the significand
Float::DIG : q = Number of decimal digits such that any floating-point number with q
decimal digits can be rounded into a floating-point number with p radix b
digits and back again without change to the q decimal digits,
q = p * log10(b) if b is a power of 10
q = floor((p - 1) * log10(b)) otherwise
((Float::MANT_DIG-1)*Math.log(FLoat::RADIX)/Math.log(10)).floor
Float::MIN_EXP : emin = Minimum int x such that Float::RADIX**(x-1) is a normalized float
Float::MIN_10_EXP : Minimum negative integer such that 10 raised to that power is in the
range of normalized floating-point numbers,
ceil(log10(b) * (emin - 1))
Float::MAX_EXP : emax = Maximum int x such that Float::RADIX**(x-1) is a representable float
Float::MAX_10_EXP : Maximum integer such that 10 raised to that power is in the range of
representable finite floating-point numbers,
floor(log10((1 - b**-p) * b**emax))
Float::MAX : Maximum representable finite floating-point number
(1 - b**-p) * b**emax
Float::EPSILON : The difference between 1 and the least value greater than 1 that is
representable in the given floating point type
b**(1-p)
Math.ldexp(*Math.frexp(1).collect{|e| e.kind_of?(Integer) ? e-(Float::MANT_DIG-1) : e})
Float::MIN : Minimum normalized positive floating-point number
b**(emin - 1).
In JRuby this is the mininimum denormal number!
Float::ROUNDS : Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown.
Note: Ruby 1.9.2 Adds Float::INFINITY and Float::NAN
Additional contants defined here:
Float::DECIMAL_DIG : Number of decimal digits, n, such that any floating-point number can be rounded
to a floating-point number with n decimal digits and back again without
change to the value,
pmax * log10(b) if b is a power of 10
ceil(1 + pmax * log10(b)) otherwise
DECIMAL_DIG = (MANT_DIG*Math.log(RADIX)/Math.log(10)).ceil+1
Float::MIN_N : Minimum normalized number == MAX_D.next == MIN (not in JRuby)
Float::MAX_D : Maximum denormal number == MIN_N.prev
Float::MIN_D : Minimum non zero positive denormal number == 0.0.next (== MIN in JRuby)
Float::MAX_F : Maximum significand
Constant Summary collapse
- DECIMAL_DIG =
(MANT_DIG*Math.log(RADIX)/Math.log(10)).ceil+1
- MIN_N =
Minimum normalized number == MAX_D.next
Math.ldexp(0.5,Float::MIN_EXP)
- MAX_D =
Maximum denormal number == MIN_N.prev
Math.ldexp(Math.ldexp(1,Float::MANT_DIG-1)-1,Float::MIN_EXP-Float::MANT_DIG)
- MIN_D =
Minimum non zero positive denormal number == 0.0.next
Math.ldexp(1,Float::MIN_EXP-Float::MANT_DIG)
- MAX_F =
Maximum significand == Math.ldexp(Math.ldexp(1,Float::MANT_DIG)-1,-Float::MANT_DIG)
Math.frexp(Float::MAX)[0]
Class Method Summary collapse
-
._sugar_context_method(*methods) ⇒ Object
:nodoc:.
-
._sugar_math_method(*methods) ⇒ Object
:nodoc:.
-
.context ⇒ Object
Return a (limited) context object for Float.
- .Num(*args) ⇒ Object
- .radix ⇒ Object
Instance Method Summary collapse
Class Method Details
._sugar_context_method(*methods) ⇒ Object
:nodoc:
44 45 46 47 48 49 50 |
# File 'lib/flt/sugar.rb', line 44 def _sugar_context_method(*methods) #:nodoc: methods.each do |method| define_method(method) do Float.context.send(method, self) end end end |
._sugar_math_method(*methods) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 |
# File 'lib/flt/sugar.rb', line 52 def _sugar_math_method(*methods) #:nodoc: methods.each do |method| define_method(method) do Math.send(method, self) end end end |
.context ⇒ Object
Return a (limited) context object for Float. This eases the implementation of functions compatible with either Num or Float values.
523 524 525 |
# File 'lib/flt/float.rb', line 523 def Float.context Flt::FloatContext.instance end |
.Num(*args) ⇒ Object
39 40 41 |
# File 'lib/flt/sugar.rb', line 39 def self.Num(*args) context.Num(*args) end |
.radix ⇒ Object
35 36 37 |
# File 'lib/flt/sugar.rb', line 35 def self.radix context.radix end |