Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10786

Cannot call modulo operator (%) on BigDecimal types

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.7
    • None
    • None

    Description

       

      It looks like org.codehaus.groovy.runtime.typehandling.BigDecimalMath does not override the default mod() method from the abstract org.codehaus.groovy.runtime.typehandling.NumberMath

      new BigInteger(5)%2 //ERROR
      new BigDecimal(5.5)%2 //ERROR
      5.5%2 //ERROR
      new Double(5.5)%2 //OK
      new Integer(5)%2 //OK
      5%2 //OK
      

       

      Caused by: java.lang.UnsupportedOperationException: Cannot use mod() on this number type: java.math.BigDecimal with value: 5.5
          at org.codehaus.groovy.runtime.typehandling.NumberMath.createUnsupportedException(NumberMath.java:316)
          at org.codehaus.groovy.runtime.typehandling.NumberMath.modImpl(NumberMath.java:296)
          at org.codehaus.groovy.runtime.typehandling.NumberMath.mod(NumberMath.java:88)
          at org.codehaus.groovy.runtime.DefaultGroovyMethods.mod(DefaultGroovyMethods.java:16201)

       

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              val235 Val E
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: