Exception: Decimal::Overflow
- Defined in:
- lib/decimal/decimal.rb
Overview
Overflow Exception.
This occurs and signals overflow if the adjusted exponent of a result (from a conversion or from an operation that is not an attempt to divide by zero), after rounding, would be greater than the largest value that can be handled by the implementation (the value Emax).
The result depends on the rounding mode:
For round-half-up and round-half-even (and for round-half-down and round-up, if implemented), the result of the operation is /-Infinity, where the sign is that of the intermediate result. For round-down, the result is the largest finite number that can be represented in the current precision, with the sign of the intermediate result. For round-ceiling, the result is the same as for round-down if the sign of the intermediate result is 1, or is Infinity otherwise. For round-floor, the result is the same as for round-down if the sign of the intermediate result is 0, or is -Infinity otherwise. In all cases, Inexact and Rounded will also be raised.
Instance Attribute Summary
Attributes inherited from Exception
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(context = nil, sign = nil, *args) ⇒ Overflow
constructor
A new instance of Overflow.
Constructor Details
#initialize(context = nil, sign = nil, *args) ⇒ Overflow
Returns a new instance of Overflow.
204 205 206 207 |
# File 'lib/decimal/decimal.rb', line 204 def initialize(context=nil, sign=nil, *args) @sign = sign super context end |
Class Method Details
.handle(context, sign, *args) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/decimal/decimal.rb', line 187 def self.handle(context, sign, *args) if [:half_up, :half_even, :half_down, :up].include?(context.rounding) Decimal.infinity(sign) elsif sign==+1 if context.rounding == :ceiling Decimal.infinity(sign) else Decimal.new([sign, Decimal.int_radix_power(context.precision) - 1, context.emax - context.precision + 1]) end elsif sign==-1 if context.rounding == :floor Decimal.infinity(sign) else Decimal.new([sign, Decimal.int_radix_power(context.precision) - 1, context.emax - context.precision + 1]) end end end |