Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / floor.rb
1 #
2 # floor.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:floor, :type => :rvalue, :doc => <<-DOC
6     @summary
7       Returns the largest integer less or equal to the argument.
8
9     @return
10       the largest integer less or equal to the argument.
11     Takes a single numeric value as an argument.
12
13     > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with
14     a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function.
15     DOC
16              ) do |arguments|
17
18     raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1
19
20     begin
21       arg = Float(arguments[0])
22     rescue TypeError, ArgumentError => _e
23       raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arguments[0]} for Numeric)")
24     end
25
26     raise(Puppet::ParseError, "floor(): Wrong argument type given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
27
28     arg.floor
29   end
30 end
31
32 # vim: set ts=2 sw=2 et :