def compute()

in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNFunctions.scala [429:473]


  def compute(value: DataValuePrimitive, precision: Int): DataValuePrimitive = {
    // We should only receive 'Numeric' types here which are either
    // xs:double, xs:float, xs:decimal, xs:integer or a sub-type thereof.
    //
    // The conversions code should be enforcing this, if not we
    // have a serious issue.
    //
    def roundIt = {
      val unroundedValue: DataValueBigDecimal = unrounded(value)
      val roundedValue = toBaseNumericType(round(unroundedValue, precision), value)
      roundedValue
    }

    val result: DataValuePrimitive = value.getAnyRef match {
      case f: JFloat
          if (f.isNaN() || f == 0 || f.floatValue().isPosInfinity || f
            .floatValue()
            .isNegInfinity) =>
        f
      case d: JDouble
          if (d.isNaN() || d == 0 || d.doubleValue().isPosInfinity || d
            .doubleValue()
            .isNegInfinity) =>
        d
      //
      // This used to be a single big case like:
      // case _:Float | _: Double | ... | _: Short => ....
      // but unfortunately, the scala compiler spit out a warning (about analyzing cases)
      // so this is equivalent, but avoids the warning.
      //
      case _: JFloat => roundIt
      case _: JDouble => roundIt
      case _: JBigDecimal => roundIt
      case _: JBigInt => roundIt
      case _: JLong => roundIt
      case _: JInt => roundIt
      case _: JByte => roundIt
      case _: JShort => roundIt
      case _ =>
        Assert.invariantFailed(
          "Unrecognized numeric type. Must be xs:float, xs:double, xs:decimal, xs:integer or a type derived from these."
        )
    }
    result
  }