Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / round.rb
1 #
2 # round.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:round, :type => :rvalue, :doc => <<-DOC
6     Rounds a number to the nearest integer
7
8     *Examples:*
9
10     round(2.9)
11
12     returns: 3
13
14     round(2.4)
15
16     returns: 2
17
18     Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
19     will be used instead of this function.
20   DOC
21              ) do |args|
22
23     raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1
24     raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric
25
26     value = args[0]
27
28     if value >= 0
29       Integer(value + 0.5)
30     else
31       Integer(value - 0.5)
32     end
33   end
34 end