Exception: Flt::Num::Overflow
- Defined in:
- lib/flt/num.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.
318 319 320 321 |
# File 'lib/flt/num.rb', line 318 def initialize(context=nil, sign=nil, *args) @sign = sign super context end |
Class Method Details
.handle(context, sign, *args) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/flt/num.rb', line 301 def self.handle(context, sign, *args) if [:half_up, :half_even, :half_down, :up].include?(context.rounding) context.num_class.infinity(sign) elsif sign==+1 if context.rounding == :ceiling context.num_class.infinity(sign) else context.num_class.new([sign, context.num_class.int_radix_power(context.precision) - 1, context.emax - context.precision + 1]) end elsif sign==-1 if context.rounding == :floor context.num_class.infinity(sign) else context.num_class.new([sign, context.num_class.int_radix_power(context.precision) - 1, context.emax - context.precision + 1]) end end end |