Class: Puppet::Pops::Types::PFloatType

Inherits:
PNumericType show all
Defined in:
lib/puppet/pops/types/types.rb

Constant Summary collapse

DEFAULT =
PFloatType.new(-Float::INFINITY)

Instance Method Summary collapse

Methods inherited from PNumericType

#eql?, #from, #hash, #initialize, #intersect?, #numeric_from, #numeric_to, #to, #unbounded?

Methods inherited from PAnyType

#==, #accept, #assignable?, #callable?, #callable_args?, #eql?, #hash, #iterable?, #iterable_type, #kind_of_callable?, #normalize, #simple_name, #to_alias_expanded_s, #to_s

Methods included from Visitable

#accept

Constructor Details

This class inherits a constructor from Puppet::Pops::Types::PNumericType

Instance Method Details

#generalizeObject



751
752
753
# File 'lib/puppet/pops/types/types.rb', line 751

def generalize
  DEFAULT
end

#instance?(o) ⇒ Boolean

Returns:

  • (Boolean)


755
756
757
# File 'lib/puppet/pops/types/types.rb', line 755

def instance?(o)
  o.is_a?(Float) && o >= numeric_from && o <= numeric_to
end

#merge(o) ⇒ PFloatType?

Concatenates this range with another range provided that the ranges intersect. When that’s not the case, this method will return ‘nil`

Parameters:

  • o (PFloatType)

    the range to concatenate with this range

Returns:

  • (PFloatType, nil)

    the concatenated range or ‘nil` when the ranges were apart



765
766
767
768
769
770
771
772
773
# File 'lib/puppet/pops/types/types.rb', line 765

def merge(o)
  if intersect?(o)
    min = @from <= o.from ? @from : o.from
    max = @to >= o.to ? @to : o.to
    PFloatType.new(min, max)
  else
    nil
  end
end