Module: Flt

Defined in:
lib/flt/complex.rb,
lib/flt/num.rb,
lib/flt/math.rb,
lib/flt/dec_num.rb,
lib/flt/version.rb,
lib/flt/support.rb,
lib/flt/bin_num.rb,
lib/flt/tolerance.rb,
lib/flt/trigonometry.rb,
lib/flt/support/reader.rb,
lib/flt/tolerance/sugar.rb,
lib/flt/support/formatter.rb,
lib/flt/support/flag_values.rb,
lib/flt/support/rationalizer.rb,
lib/flt/support/rationalizer_extra.rb

Overview

Complex

Defined Under Namespace

Modules: BigEpsilonMixin, EpsilonMixin, MathBase, Support, Trigonometry Classes: AbsBigEpsilonTolerance, AbsEpsilonTolerance, AbsoluteTolerance, BigDecimalContext, BigEpsilonTolerance, BinNum, ComplexContext, DecNum, DecimalsTolerance, EpsilonTolerance, FloatContext, FloatingTolerance, FltBigEpsilonTolerance, FltEpsilonTolerance, Num, PercentTolerance, PermilleTolerance, RelativeTolerance, SigBitsTolerance, SigDecimalsTolerance, Tolerance, UlpsTolerance

Constant Summary collapse

VERSION =
"1.5.0"

Class Method Summary collapse

Class Method Details

.BinNum(*args) ⇒ Object


249
250
251
# File 'lib/flt/bin_num.rb', line 249

def BinNum(*args)
  BinNum.Num(*args)
end

.ComplexContext(context) ⇒ Object


294
295
296
# File 'lib/flt/complex.rb', line 294

def ComplexContext(context)
  ComplexContext.new(context)
end

.DecNum(*args) ⇒ Object

DecNum constructor. See DecNum#new for the parameters. If a DecNum is passed a reference to it is returned (no new object is created).


1215
1216
1217
# File 'lib/flt/dec_num.rb', line 1215

def DecNum(*args)
  DecNum.Num(*args)
end

.float_correctly_rounded?Boolean

Is Float('…') correctly rounded, even for subnormal numbers?

Returns:

  • (Boolean)

530
531
532
533
# File 'lib/flt/float.rb', line 530

def Flt.float_correctly_rounded?
  # That doesn't seem to be the case for mswin32
  @float_correctly_rounded ||= RUBY_PLATFORM.match(/mswin32/).nil?
end

.Tolerance(*args) ⇒ Object

Tolerance constructor.

The first parameter is the value (magnitude) of the tolerance, and is optional for some tolerances.

The next parameter is the kind of tolerance as a symbol. It corresponds to the name of the implementation class minus the Tolerance suffix, and converted to snake-case (lowercase with underscores to separate words.)

Finally any additional parameters admitted by the class constructor can be passed.


551
552
553
554
555
556
557
558
559
560
# File 'lib/flt/tolerance.rb', line 551

def Tolerance(*args)
  return args.first if args.size == 1 && Tolerance === args.first
  if args.first.is_a?(Symbol)
    value = nil
  else
    value = args.shift
  end
  cls_name = (args.shift || :absolute).to_s.gsub(/(^|_)(.)/){$2.upcase} + "Tolerance"
  Flt.const_get(cls_name).new(value, *args)
end