lib/rdf/model/literal/double.rb in rdf-1.0.10.2 vs lib/rdf/model/literal/double.rb in rdf-1.1.0.p0
- old
+ new
@@ -48,11 +48,11 @@
when @object.zero? then '0.0E0'
else
i, f, e = ('%.15E' % @object.to_f).split(/[\.E]/)
f.sub!(/0*$/, '') # remove any trailing zeroes
f = '0' if f.empty? # ...but there must be a digit to the right of the decimal point
- e.sub!(/^(?:\+|(\-))?0+(\d+)$/, '\1\2') # remove the optional leading '+' sign and any extra leading zeroes
+ e.sub!(/^\+?0+(\d)$/, '\1') # remove the optional leading '+' sign and any extra leading zeroes
"#{i}.#{f}E#{e}"
end
@object = Float(@string) unless @object.nil?
self
end
@@ -116,53 +116,45 @@
def infinite?
to_f.infinite?
end
##
- # Returns the smallest number greater than or equal to `self`.
+ # Returns the smallest integer greater than or equal to `self`.
#
# @example
# RDF::Literal(1.2).ceil #=> RDF::Literal(2)
# RDF::Literal(-1.2).ceil #=> RDF::Literal(-1)
# RDF::Literal(2.0).ceil #=> RDF::Literal(2)
# RDF::Literal(-2.0).ceil #=> RDF::Literal(-2)
#
# @return [RDF::Literal]
# @since 0.2.3
def ceil
- self.class.new(to_f.ceil)
+ RDF::Literal(to_f.ceil)
end
##
- # Returns the largest number less than or equal to `self`.
+ # Returns the largest integer less than or equal to `self`.
#
# @example
# RDF::Literal(1.2).floor #=> RDF::Literal(1)
# RDF::Literal(-1.2).floor #=> RDF::Literal(-2)
# RDF::Literal(2.0).floor #=> RDF::Literal(2)
# RDF::Literal(-2.0).floor #=> RDF::Literal(-2)
#
# @return [RDF::Literal]
# @since 0.2.3
def floor
- self.class.new(to_f.floor)
+ RDF::Literal(to_f.floor)
end
##
# Returns the absolute value of `self`.
#
# @return [RDF::Literal]
# @since 0.2.3
def abs
- (f = to_f) && f > 0 ? self : self.class.new(f.abs)
- end
-
- ##
- # Returns the number with no fractional part that is closest to the argument. If there are two such numbers, then the one that is closest to positive infinity is returned. An error is raised if arg is not a numeric value.
- #
- # @return [RDF::Literal]
- def round
- self.class.new(to_f.round)
+ (f = to_f) && f > 0 ? self : RDF::Literal(f.abs)
end
##
# Returns `true` if the value is zero.
#