[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

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.


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.

Comment by Henrik Lindberg [ 2016/09/13 ]

Merged to master at: 4cdb8a9

Comment by Henrik Lindberg [ 2016/09/13 ]

Just realized that an update to the documentation in new is also needed.

Generated at Fri Jun 05 19:24:29 PDT 2020 using Jira 8.5.2#805002-sha1:a66f9354b9e12ac788984e5d84669c903a370049.