Uploaded image for project: 'Commons Numbers'
  1. Commons Numbers
  2. NUMBERS-205

Add isZero() to interface Addition and isOne() to Multiplications

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Implemented
    • 1.1
    • 1.2
    • core
    • None
    • Easy

    Description

      Rationale

      While coding polynomial computations over differing fields with commons math3 where the field is a generic parameter in the implementation of monomials and polynomials, I coded the comparison with zero and one as coefficient.getField().getZero().equals(coefficient).

      With commons-numbers this gets slightly less cumbersome as coefficient.zero().equals(coefficient), but cumbersome and somewhat weird looking it is still.

      But the look of it is not the only problem: employing async-profiler I saw that the equals() required a non-negligible amount of CPU power, in particular for the BigFraction field, which in some cases near-duplicates the value to be compared due to calls to negate().

      Requirement

      • Add a method isZero() to interface Addition which returns true iff the object is semantically equivalent to the object returned by zero().
      • Add a method isOne() to interface Multiplication which returns true iff the object is semantically equivalent to the value returned by one().

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              haraldk Harald Kirsch
              Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: