removed redundant math functions as jinja2 provides abs() and round()

already
pull/9832/head
Brian Coca 10 years ago
parent 6a3c26eb70
commit b07ce8b942

@ -318,19 +318,11 @@ Math
--------------------
.. versionadded:: 1.9
To get the absolute value of a number::
{{ -23 | abs }}
To see if something is actually a number::
{{ myvar | isnan }}
Rounding::
{{ myvar | ceil }}
{{ myvar | floor }}
Get the logarithm (default is e)::
{{ myvar | log }}
@ -349,6 +341,8 @@ Square root, or the 5th::
{{ myvar | root }}
{{ myvar | root(5) }}
Note that jinja2 already provides some like abs() and round().
.. _other_useful_filters:

@ -18,30 +18,6 @@
import math
from ansible import errors
def absolute(x):
if isinstance(x, float):
return math.fabs(x)
elif isinstance(x, int):
return abs(x)
else
raise errors.AnsibleFilterError('abs() can only be used on numbers')
def cieling(x):
try:
return math.ciel(x)
except TypeError, e:
raise errors.AnsibleFilterError('ciel() can only be used on floats: %s' % str(e))
def flooring(x):
try:
return math.floor(x)
except TypeError, e:
raise errors.AnsibleFilterError('floor() can only be used on floats: %s' % str(e))
def isnotanumber(x):
try:
return math.isnan(x)
@ -82,13 +58,8 @@ class FilterModule(object):
def filters(self):
return {
# general math
'abs': absolute,
'isnan': isnotanumber,
# rounding
'ceil': cieling,
'floor': flooring,
# exponents and logarithms
'log': logarithm,
'pow': power,

Loading…
Cancel
Save