Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-6291

Add 'abs' support to Numeric.new

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.8.0
    • Component/s: None
    • Template:
    • Acceptance Criteria:
      Hide

      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.

      Show
      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:
    • Team:
      Puppet Developer Experience
    • Story Points:
      1
    • Sprint:
      PDS 2016-09-21, PDS 2016-10-05
    • Release Notes:
      New Feature
    • Release Notes Summary:
      Hide
      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.
      Show
      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.

        Attachments

          Activity

            jsd-sla-details-panel

              People

              • Assignee:
                Unassigned
                Reporter:
                henrik.lindberg Henrik Lindberg
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: