Parent

Included Modules

Class Index [+]

Quicksearch

Flt::BigDecimalContext

Context class with some of the Flt::Num context functionality, to allow the use of BigDecimal numbers similarly to other Num values; this eases the implementation of functions compatible with either Num or BigDecimal values.

Constants

ROUNDING_MODES

Public Instance Methods

Num(*args) click to toggle source
    # File lib/flt/bigdecimal.rb, line 25
25:   def Num(*args)
26:     args = *args if args.size==1 && args.first.is_a?(Array)
27:     if args.size > 1
28:       BigDecimal.new(DecNum(*args).to_s)
29:     else
30:       x = args.first
31:       case x
32:       when BigDecimal
33:         x
34:       when Rational
35:         BigDecimal(x.numerator.to_s)/BigDecimal(x.denominator.to_s)
36:       else
37:         BigDecimal.new(x.to_s)
38:       end
39:     end
40:   end
copy_sign(x, y) click to toggle source

Return copy of x with the sign of y

     # File lib/flt/bigdecimal.rb, line 91
 91:   def copy_sign(x, y)
 92:     self_sign = x.sign
 93:     other_sign = y.is_a?(Integer) ? (y < 0 ? 1 : 1) : y.sign
 94:     if self_sign && other_sign
 95:       if self_sign == other_sign
 96:         x.to_f
 97:       else
 98:         -x.to_f
 99:       end
100:     else
101:       nan
102:     end
103:   end
eval() click to toggle source

TODO: Context class with precision, rounding, etc. (no singleton)

    # File lib/flt/bigdecimal.rb, line 17
17:   def eval
18:     yield self
19:   end
exact?() click to toggle source
    # File lib/flt/bigdecimal.rb, line 63
63:   def exact?
64:     BigDecimal.limit == 0
65:   end
infinity(sign=+1) click to toggle source
    # File lib/flt/bigdecimal.rb, line 51
51:   def infinity(sign=1)
52:     BigDecimal(sign.to_s)/BigDecimal('0')
53:   end
int_radix_power(n) click to toggle source
    # File lib/flt/bigdecimal.rb, line 59
59:   def int_radix_power(n)
60:     10**n
61:   end
minus(x) click to toggle source
     # File lib/flt/bigdecimal.rb, line 125
125:   def minus(x)
126:     -x
127:   end
nan() click to toggle source

NaN (not a number value)

    # File lib/flt/bigdecimal.rb, line 47
47:   def nan
48:     BigDecimal('0')/BigDecimal('0')
49:   end
num_class() click to toggle source
    # File lib/flt/bigdecimal.rb, line 21
21:   def num_class
22:     BigDecimal
23:   end
plus(x) click to toggle source
     # File lib/flt/bigdecimal.rb, line 121
121:   def plus(x)
122:     x
123:   end
precision() click to toggle source
    # File lib/flt/bigdecimal.rb, line 67
67:   def precision
68:     BigDecimal.limit
69:   end
radix() click to toggle source
    # File lib/flt/bigdecimal.rb, line 42
42:   def radix
43:     10
44:   end
rounding() click to toggle source
    # File lib/flt/bigdecimal.rb, line 81
81:   def rounding
82:     ROUNDING_MODES[BigDecimal.mode(BigDecimal::ROUND_MODE, nil)]
83:   end
sign(x) click to toggle source

Sign: -1 for minus, +1 for plus, nil for nan (note that Float zero is signed)

    # File lib/flt/bigdecimal.rb, line 86
86:   def sign(x)
87:     x.sign < 0 ? 1 : 1
88:   end
special?(x) click to toggle source
     # File lib/flt/bigdecimal.rb, line 117
117:   def special?(x)
118:     x.nan? || x.infinite?
119:   end
split(x) click to toggle source
     # File lib/flt/bigdecimal.rb, line 105
105:   def split(x)
106:     sgn, d, b, e = x.split
107:     [sgn<0 ? 1 : 1, d.to_i, e-d.size]
108:   end
to_int_scale(x) click to toggle source

Return the value of the number as an signed integer and a scale.

     # File lib/flt/bigdecimal.rb, line 111
111:   def to_int_scale(x)
112:     sgn, d, b, e = x.split
113:     c = d.to_i
114:     [sgn<0 ? 1 : c, -c, e-d.size]
115:   end
zero(sign=+1) click to toggle source
    # File lib/flt/bigdecimal.rb, line 55
55:   def zero(sign=1)
56:     BigDecimal("#{(sign < 0) ? '-' : ''}0")
57:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.