[PUP-6291] Add 'abs' support to Numeric.new Created: 2016/05/11  Updated: 2016/11/02  Resolved: 2016/09/26

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 4.8.0

 Type: New Feature Priority: Normal Reporter: Henrik Lindberg Assignee: Unassigned Resolution: Fixed Votes: 0 Labels: low-hanging-fruit Remaining Estimate: Not Specified Time Spent: Not Specified Original Estimate: Not Specified

 Template: customfield_10700 131127 Acceptance Criteria: That an optional (second) boolean argument to the new method on Integer, Float or Numeric makes the conversion to a number return an absolute value if the boolean is true and a positive or negative value (depending on the input) otherwise. Epic Link: 4.x Language Team: Puppet Developer Experience Story Points: 1 Sprint: PDS 2016-09-21, PDS 2016-10-05 Release Notes: New Feature Release Notes Summary: It is now possible to specify that an absolute (positive) value is wanted when creating a new Integer, Float, or abstractly via Numeric by passing a second optional boolean argument to the {{new}} function where {{true}} means that an absolute value is wanted. For example {{Numeric.new(\$str, true)}} which converts the numerical value in string form (with a possible leading minus) to an absolute value.

 Description

The Numeric, Integer, and Float new should take an extra named argument Boolean abs that will make the conversion perform abs(result) before returning it.

 `\$x = "-123"` ```\$a = Numeric({from => \$x, abs => true }) ```

The non named argument variants can also get an extra optional parameter for abs. For Integer it means having to specify the radix if abs is also wanted.

 `\$x = "-123"` ```\$a = Numeric(\$x, true) ```

For Integer, a negative radix could be used to mean absolute value. This is perhaps a bit too magic, but if read "a negative value is negated" it is kind of ok.

This removes the need for the stdlib abs() function.