4 module Puppet::Parser::Functions
5 newfunction(:abs, :type => :rvalue, :doc => <<-DOC
7 **Deprecated:** Returns the absolute value of a number
9 For example -34.56 becomes 34.56.
10 Takes a single integer or float value as an argument.
13 **Deprected** from Puppet 6.0.0, the built-in
14 ['abs'](https://puppet.com/docs/puppet/6.4/function.html#abs)function will be used instead.
16 @return The absolute value of the given number if it was an Integer
21 raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
25 # Numbers in Puppet are often string-encoded which is troublesome ...
26 if value.is_a?(String)
27 if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$}
29 elsif value =~ %r{^-?\d+$}
32 raise(Puppet::ParseError, 'abs(): Requires float or integer to work with')
36 # We have numeric value to handle ...
43 # vim: set ts=2 sw=2 et :