Class: Float

Inherits:
Object
show all
Defined in:
lib/flt/float.rb,
lib/flt/sugar.rb

Overview

Float constants.

Note that this uses the “fractional significand” interpretation, i.e. the significand has the radix point before its first digit.

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::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

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
``````

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]   == Math.ldexp(Math.ldexp(1,Float::MANT_DIG)-1,-Float::MANT_DIG)
```

Class Method Summary collapse

• :nodoc:.

• :nodoc:.

• Return a (limited) context object for Float.

Class Method Details

._sugar_context_method(*methods) ⇒ Object

:nodoc:

 ``` 45 46 47 48 49 50 51``` ```# File 'lib/flt/sugar.rb', line 45 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:

 ``` 53 54 55 56 57 58 59``` ```# File 'lib/flt/sugar.rb', line 53 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.

 ``` 525 526 527``` ```# File 'lib/flt/float.rb', line 525 def Float.context Flt::FloatContext.instance end ```

.Num(*args) ⇒ Object

 ``` 40 41 42``` ```# File 'lib/flt/sugar.rb', line 40 def self.Num(*args) context.Num(*args) end ```

 ``` 36 37 38``` ```# File 'lib/flt/sugar.rb', line 36 def self.radix context.radix end ```
 ``` 66 67 68``` ```# File 'lib/flt/sugar.rb', line 66 def next_toward(other) Float.context.next_toward(self, other) end ```