4 module Puppet::Parser::Functions
5 newfunction(:abs, :type => :rvalue, :doc => <<-DOC
6 Returns the absolute value of a number, for example -34.56 becomes
7 34.56. Takes a single integer and float value as an argument.
9 Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
10 will be used instead of this function.
14 raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
18 # Numbers in Puppet are often string-encoded which is troublesome ...
19 if value.is_a?(String)
20 if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$}
22 elsif value =~ %r{^-?\d+$}
25 raise(Puppet::ParseError, 'abs(): Requires float or integer to work with')
29 # We have numeric value to handle ...
36 # vim: set ts=2 sw=2 et :