a mod b

Calculates the modulo of a and b. This is the remaining value after a division of a and b.

Description of Parameters

Parameter

Description

a

Value.

b

Modulus.

Notes on Data Types

Result Data Type

The result data type of the function depends on the data type of parameter a. Parameter b and consequently the result are always implicitly converted to the data type of parameter a. There are three possibilities:

  • If parameter a is of type BigInteger, parameter b is converted into BigInteger and the result is BigInteger.

  • If parameter a is of type BigDecimal, parameter b is converted into BigDecimal and the result is BigDecimal.

  • If parameter a is neither of type BigInteger nor of type BigDecimal, it is always converted into Double. Parameter b is also converted into Double and the result is Double.

Further Notes on Data Types

  • The data type Double should be handled with caution, as it can lead to unpleasant decimal effects. See examples below. This is not a programming error but is due to general representation problems with binary numbers, which will not be discussed in more detail here.

  • In addition to implicit type conversion within the function, implicit type conversion in fields of the destination structure must also be considered (that applies to parameter fields and also to the result field). If a destination structure field, for example, has the data type Integer and gets the value 7.2, the field value is implicitly converted into 7.

  • For the explicit conversion of data types, the functions convert-type(value a, type b, mask c)convert2BigInt(a[, b]) can be used.

Examples

Parameter a

Parameter b

Result

Explanation

10 (Type: BigInteger)

2 (Type: BigInteger)

0 (Type: BigInteger)

10 = 5 * 2, remainder 0.

10 (Type: BigInteger)

4 (Type: BigInteger)

2 (Type: BigInteger)

10 = 2 * 4, remainder 2.

7.2 (Type: BigDecimal)

2.1 (Type: BigDecimal)

0.9 (Type: BigDecimal)

7.2 = 3 * 2.1, remainder 0.9.

7.2 (Type: Double)

2.1 (Type: Double)

0.8999999999999999 (Type: Double)

Here we get a representational problem in the result with data type Double.

7 (Type: String)

2 (Type: String)

1.0 (Type: Double)

The datatype of parameter a is implicitly converted from String into Double. Therefore, parameter b is also converted into type Double and the result is of type Double.

7 (Type: BigInteger)

2.1 (Type: Double)

1 (Type: BigInteger)

The datatype of parameter b is implicitly converted from Double into BigInteger. Therefore the result is also of type BigInteger. 7 = 3 * 2, remainder 1.

10 (Type: Integer)

4 (Type: Integer)

2.0 (Type: Double)

Since parameter a is neither of type BigInteger nor of type BigDecimal, it is converted into Double. Therefore, parameter b is also converted into type Double and the result is of type Double.