Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented the RDF::Literal::Double#ceil and #floor methods.
  • Loading branch information
artob committed Aug 24, 2010
1 parent a33a5fd commit 6027fa2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/rdf/model/literal/double.rb
Expand Up @@ -54,6 +54,11 @@ def canonicalize
##
# Returns `true` if the value is an invalid IEEE floating point number.
#
# @example
# RDF::Literal(-1.0).nan? #=> false
# RDF::Literal(1.0/0.0).nan? #=> false
# RDF::Literal(0.0/0.0).nan? #=> true
#
# @return [Boolean]
# @since 0.2.3
def nan?
Expand All @@ -64,6 +69,11 @@ def nan?
# Returns `true` if the value is a valid IEEE floating point number (it
# is not infinite, and `nan?` is `false`).
#
# @example
# RDF::Literal(-1.0).finite? #=> true
# RDF::Literal(1.0/0.0).finite? #=> false
# RDF::Literal(0.0/0.0).finite? #=> false
#
# @return [Boolean]
# @since 0.2.3
def finite?
Expand All @@ -74,12 +84,47 @@ def finite?
# Returns `nil`, `-1`, or `+1` depending on whether the value is finite,
# `-INF`, or `+INF`.
#
# @example
# RDF::Literal(0.0/0.0).infinite? #=> nil
# RDF::Literal(-1.0/0.0).infinite? #=> -1
# RDF::Literal(+1.0/0.0).infinite? #=> 1
#
# @return [Integer]
# @since 0.2.3
def infinite?
to_f.infinite?
end

##
# 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
RDF::Literal(to_f.ceil)
end

##
# 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
RDF::Literal(to_f.floor)
end

##
# Returns the absolute value of `self`.
#
Expand Down

0 comments on commit 6027fa2

Please sign in to comment.