Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8301226 Add clamp() methods to java.lang.Math and to StrictMath
  3. JDK-8315443

Release Note: `Math.clamp()` and `StrictMath.clamp()` Methods

    XMLWordPrintable

Details

    Description

      The methods `Math.clamp()` and `StrictMath.clamp()` are added to conveniently clamp the numeric value between the specified minimum and maximum values. Four overloads are provided in both `Math` and `StrictMath` classes for `int`, `long`, `float`, and `double` types. A `clamp(long value, int min, int max)` overload can also be used to safely narrow a `long` value to `int`.

      Attachments

        Activity

          People

            tvaleev Tagir Valeev
            tvaleev Tagir Valeev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: