Select Page ## Logic Apps (Standard) Data Mapper: Math (or Mathematical) Functions (Part 2)

Because the Math (or Mathematical) functions category has too many functions, I decide to break this blog post into different parts, so welcome to the second part!

## Overview

Math (or Mathematical) functions are used to perform a variety of mathematical and scientific operations, such as addition and multiplication. If you come from the BizTalk Server background or are migrating BizTalk Server projects, they are the equivalent of Mathematical and Scientific Functoids inside BizTalk Mapper Editor.

## Available Functions

The Math functions are:

• Absolute: Returns the absolute value of the specified number.
• Arctangent: Returns the arc tangent of a number.
• Ceiling: Returns the smallest integral value greater than or equal to the specified number.
• Cosine: Returns the cosine for the specified angle.
• Divide: Returns the result from dividing two numbers.
• Exponential: Raises the “e” constant to the specified power and returns the result.
• Exponential (base 10): Returns the number 10 raised to the specified power.
• Floor: Returns the largest integral value less than or equal to the specified number.
• Integer divide: Divides two numbers and returns the integer part from the result.
• Log: Returns the logarithm for the specified number in the specified base.
• Log (base 10): Returns the base 10 logarithm for the specified number.
• Modulo: Returns the remainder from dividing the specified numbers.
• Multiply: Returns the product from multiplying two or more specified numbers.
• Power: Returns the specified number raised to the specified power.
• Round: Rounds a value to the nearest integer or the specified number of fractional digits and returns the result.
• Sine: Returns the sine for the specified angle.
• Square root: Returns the square root for the specified number.
• Subtract: Subtracts the second number from the first number and returns the result.
• Tangent: Returns the tangent for the specified angle.

## Log

This function states that it will return the logarithm for the specified number in the specified base.

Behind the scenes, this function is translated to the following XPath function: math:log(\$arg)

• `math:log`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• The result is the natural logarithm of `\$arg`

Sample:

• The expression `math:log(0)` returns `xs:double('-INF')`.
• The expression `math:log(-1)` returns `xs:double('NaN')`.
• The expression `math:log(2)` returns `0.6931471805599453`

## Log (base 10)

This function states that it will return the base 10 logarithm for the specified number.

Behind the scenes, this function is translated to the following XPath function: math:log10(\$arg)

• `math:log10`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• The result is the base-10 logarithm of `\$arg`

Sample:

• The expression `math:log10(0)` returns `xs:double('-INF')`
• The expression `math:log10(2)` returns `0.3010299956639812`
• The expression `math:log10(-1)` returns `xs:double('NaN')`

## Modulo

This function states that it will return the remainder from dividing the specified numbers.

Behind the scenes, this function is translated to the following XPath expression: (\$arg1) mod (\$arg2)

• `fn:error`(`\$code as xs:QName?``\$description as xs:string`)` as none`

Rules:

• Returns the remainder resulting from dividing `\$arg1`, the dividend, by `\$arg2`, the divisor.
• The operation `a mod b` for operands that are `xs:integer` or `xs:decimal`, or types derived from them, produces a result such that `(a idiv b)*b+(a mod b)` is equal to `a` and the magnitude of the result is always less than the magnitude of `b`. This identity holds even in the special case that the dividend is the negative integer of largest possible magnitude for its type and the divisor is -1 (the remainder is 0). It follows from this rule that the sign of the result is the sign of the dividend.

Sample:

• The expression `(10) mod (3)` returns `1`.
• The expression `(6) mod (-2)` returns `0`.
• The expression `(4.5) mod (1.2)` returns `0.9`.

## Multiply

This function states that it will return the product from multiplying two or more specified numbers.

Behind the scenes, this function is translated to the following XPath expression: (\$arg1) * (\$arg2) (allows more inputs)

• (\$arg1) * (\$arg2) `as xs:numeric?`

Rules:

• Returns the arithmetic product of its operands: (`\$arg1 * \$arg2`).
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` then the result may be an instance of `xs:integer`.
• This function allows two or more inputs.

Sample:

• The expression (`5) + (2)` returns `10`.
• The expression (`5.1) + (2)` returns `10.2`.

## Power

This function states that it will return the specified number raised to the specified power.

Behind the scenes, this function is translated to the following XPath function: math:pow(\$arg1, \$arg2)

• `math:pow`(`\$arg1 as xs:double?``\$arg2 as xs:numeric`)` as xs:double?`

Rules:

• If `\$arg2` is an instance of `xs:integer`, the result is `\$arg1` raised to the power of `\$arg2`. Otherwise `\$arg2` is converted to an `xs:double` by numeric promotion, and the result is the value of `\$arg1` raised to the power of `\$arg2`.

Sample:

• The expression `math:pow(2, 3)` returns `8`.
• The expression `math:pow(-2, 3)` returns `-8`
• The expression `math:pow(2, 0)` returns `1`
• The expression `math:pow(2.5, 2)` returns 6.25

## Round

This function states that it will round a value to the nearest integer or the specified number of fractional digits and returns the result.

Behind the scenes, this function is translated to the following XPath function: round(\$arg1, \$arg2)

• `fn:round`(`\$arg as xs:numeric?``\$precision as xs:integer`)` as xs:numeric?`

Rules:

• The function returns the nearest (that is, numerically closest) value to `\$arg` that is a multiple of ten to the power of minus `\$precision`. If two such values are equally near (for example, if the fractional part in `\$arg` is exactly .5), the function returns the one that is closest to positive infinity.
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` and `\$precision` is less than one, then the result may be an instance of `xs:integer`.

Sample:

• The expression `fn:round(1.125, 2)` returns `1.13`
• The expression `fn:round(8452, -2)` returns `8500`

## Sine

This function states that it will return the sine for the specified angle.

Behind the scenes, this function is translated to the following XPath function: math:sin(\$arg)

• `math:sin`(`\$`arg` as xs:double?`)` as xs:double?`

Rules:

• If `\$`arg is positive or negative zero, the result is `\$`arg.
• Returns the sine of the argument. The argument is an angle in radians.

Sample:

• The expression `math:sin(0)` returns `0`.
• The expression `math:sin(45)` returns `0.8509035245341184`.

## Square root

This function states that it will return the square root for the specified number.

Behind the scenes, this function is translated to the following XPath function: math:sqrt(\$arg)

• `math:sqrt`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• If `\$arg` is positive or negative zero, positive infinity, or `NaN`, then the result is `\$arg`. (Negative zero is the only case where the result can have negative sign)
• The result is the mathematical non-negative square root of `\$arg`

Sample:

• The expression `math:sqrt(0)` returns `0`.
• The expression `math:sqrt(-2)` returns `NaN.`
• The expression `math:sqrt(4)` returns `2`.

## Subtract

This function states that it will subtract the second number from the first number and returns the result.

Behind the scenes, this function is translated to the following XPath function: (`\$arg1) - (\$arg2`)

• `(\$arg1 as xs:numeric - \$arg2 as xs:numeric) as xs:numeric`

Rules:

• Returns the arithmetic difference of its operands: (`\$arg1 - \$arg2`).
• `\$arg1 and \$arg2` are numeric values (`xs:float``xs:double``xs:decimal` and `xs:integer`)

Sample:

• The expression (`3) - (1)` returns `2`.
• The expression (2`) - (1.12)` returns `0.88`.

## Tangent

This function states that it will return the tangent for the specified angle.

Behind the scenes, this function is translated to the following XPath function: math:tan(\$arg)

• `math:tan`(`\$`arg` as xs:double?`)` as xs:double?`

Rules:

• If `\$`arg is positive or negative infinity, or `NaN`, then the result is `NaN`.
• Returns the tangent of the argument. The argument is an angle in radians.

Sample:

• The expression `math:tan(0)` returns `0`
• The expression math:tan(12) returns `-0.6358599286615808`

Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help buy) my son a Star Wars Lego! ##### Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.

He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community. ## Overview

Math (or Mathematical) functions are used to perform a variety of mathematical and scientific operations, such as addition and multiplication. If you come from the BizTalk Server background or are migrating BizTalk Server projects, they are the equivalent of Mathematical and Scientific Functoids inside BizTalk Mapper Editor.

## Available Functions

The Math functions are:

• Absolute: Returns the absolute value of the specified number.
• Arctangent: Returns the arc tangent of a number.
• Ceiling: Returns the smallest integral value greater than or equal to the specified number.
• Cosine: Returns the cosine for the specified angle.
• Divide: Returns the result from dividing two numbers.
• Exponential: Raises the “e” constant to the specified power and returns the result.
• Exponential (base 10): Returns the number 10 raised to the specified power.
• Floor: Returns the largest integral value less than or equal to the specified number.
• Integer divide: Divides two numbers and returns the integer part from the result.
• Log: Returns the logarithm for the specified number in the specified base.
• Log (base 10): Returns the base 10 logarithm for the specified number.
• Modulo: Returns the remainder from dividing the specified numbers.
• Multiply: Returns the product from multiplying two or more specified numbers.
• Power: Returns the specified number raised to the specified power.
• Round: Rounds a value to the nearest integer or the specified number of fractional digits and returns the result.
• Sine: Returns the sine for the specified angle.
• Square root: Returns the square root for the specified number.
• Subtract: Subtracts the second number from the first number and returns the result.
• Tangent: Returns the tangent for the specified angle.

## Absolute

This function states that it will return the absolute value of the specified number.

Behind the scenes, this function is translated to the following XPath function: abs(\$arg)

• `fn:abs`(`\$arg as xs:numeric?`)` as xs:numeric?`

Rules:

• If `\$arg` is negative, the function returns `-\$arg`. Otherwise, it returns `\$arg`.
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:positiveInteger` then the value of `\$arg` may be returned unchanged.
• For `xs:float` and `xs:double` arguments, if the argument is positive zero or negative zero, then positive zero is returned. If the argument is positive or negative infinity, positive infinity is returned.

Sample:

• The expression `fn:abs(10.5)` returns `10.5`.
• The expression `fn:abs(-10.5)` returns `10.5`.

This function states that it will return the sum from adding two or more numbers.

Behind the scenes, this function is translated to the following XPath expression: \$arg1 + \$arg2 (allows more inputs)

• `(\$arg1 as xs:numeric + \$arg2 as xs:numeric) as xs:numeric`

Rules:

• Returns the arithmetic sum of its operands: (`\$arg1 + \$arg2`).
• `\$arg1 and \$arg2` are numeric values (`xs:float``xs:double``xs:decimal` and `xs:integer`)
• This function allows two or more inputs.

Sample:

• The expression (`1) + (3)` returns `4`.
• The expression (`1.12) + (2)` returns `3.12`.

## Arctangent

This function states that it will return the arc tangent of a number.

Behind the scenes, this function is translated to the following XPath function: math:atan(\$arg)

• `math:atan`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• If `\$arg` is a non-numeric value, then the result is `empty`.

Sample:

• The expression `math:atan(0)` returns `0`.
• The expression `math:atan(1.28)` returns `0.9075933340888034`.

## Ceiling

This function states that it will return the smallest integral value greater than or equal to the specified number.

Behind the scenes, this function is translated to the following XPath function: ceiling(\$arg)

• `fn:ceiling`(`\$arg as xs:numeric?`)` as xs:numeric?`

Rules:

• The function returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of `\$arg`.
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` then the result may be an instance of `xs:integer`.

Sample:

• The expression `fn:ceiling(10.5)` returns `11`.
• The expression `fn:ceiling(-10.5)` returns `-10`.

## Cosine

This function states that it will return the cosine for the specified angle.

Behind the scenes, this function is translated to the following XPath function: math:cos(\$arg)

• `math:cos`(`\$`arg` as xs:double?`)` as xs:double?`

Rules:

• If `\$`arg is positive or negative zero, the result is `\$`arg.

Sample:

• The expression `math:cos(0)` returns `1`
• The expression `math:cos(1212)` returns 0.7931914936378434

## Divide

This function states that it will return the result from dividing two numbers.

Behind the scenes, this function is translated to the following XPath function: \$arg1 div \$arg2

• \$arg1 div \$arg2` as xs:numeric?`

Rules:

• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` then the result may be an instance of `xs:integer`.

Sample:

• The expression `(10) div (3)` returns `3`.
• The expression `(-3) div (-2)` returns `1.5`.
• The expression `(-3) div (2)` returns `-1`.
• The expression `(-3.5) div (3)` returns `0.7`.

## Exponential

This function states that it will raise the “e” constant to the specified power and returns the result.

Behind the scenes, this function is translated to the following XPath function: math:exp(\$arg)

• `math:exp`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• Returns the value of e

Sample:

• The expression `math:exp(0)` returns `1`.
• The expression `math:exp(1)` returns `2.7182818284590455`.

## Exponential (base 10)

This function states that it will return the number 10 raised to the specified power.

Behind the scenes, this function is translated to the following XPath function: math:exp10(\$arg)

• `math:exp10`(`\$arg as xs:double?`)` as xs:double?`

Rules:

• Returns the value of `10`

Sample:

• The expression `math:exp10(0)` returns `1`
• The expression `math:exp10(1)` returns `1.0e1`.
• The expression `math:exp10(0.5)` returns `3.1622776601683795`

## Floor

This function states that it will return the largest integral value less than or equal to the specified number.

Behind the scenes, this function is translated to the following XPath function: floor(\$arg)

• `fn:error`(`\$code as xs:QName?``\$description as xs:string`)` as none`

Rules:

• The function returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of `\$arg`.
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` then the result may be an instance of `xs:integer`.

Sample:

• The expression `fn:floor(10.5)` returns `10`.
• The expression `fn:floor(10.9)` returns `10`.
• The expression `fn:floor(-10.5)` returns `-11`.

## Integer divide

This function states that it will divide two numbers and returns the integer part from the result.

Behind the scenes, this function is translated to the following XPath expression: (\$arg1) idiv (\$arg2)

• `(\$arg1) idiv (\$arg2) as xs:integer`

Rules:

• Performs an integer division.
• For the four types `xs:float``xs:double``xs:decimal` and `xs:integer`, it is guaranteed that if the type of `\$arg` is an instance of type T then the result will also be an instance of T. The result may also be an instance of a type derived from one of these four by restriction. For example, if `\$arg` is an instance of `xs:decimal` then the result may be an instance of `xs:integer`.

Sample:

• The expression `(10) idiv (3)` returns `3`.
• The expression `(-3) idiv (-2)` returns `1`.
• The expression `(-3) idiv (2)` returns `-1`.
• The expression `(-3.5) idiv (3)` returns `-1`.

Stay tune for the second part of this blog post.

Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help buy) my son a Star Wars Lego! ##### Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.

He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community. ## BizTalk Mapper Extensions UtilityPack: New Math Functoids

And once again I decide to publish another release on my Mapper Extensions UtilityPack project adding new functionalities to this toolset. This time I decided to release 2 new BizTalk Math Functoids:

• Negate Number Functoid: You can use the Negate Number functoid to return the input number (double) in its negated form.
• If it’s positive, it will return as negative and vice-versa.
• If zero, of course, will return zero.
• SmartRound Functoid: You can use the SmartRound Functoid to return any number (int or double) rounded up or down to any decimal place, specified by the second parameter of this functoid.

## Negate Number Functoid

Use the Negate Number functoid to return the input number (double) in its negated form.

### Parameters

The functoid takes one mandatory input parameter:

1. Parameter 1: Number to be negated (double or int).

The output of the functoid will be the input number in is negative form. For example:

• Input 1 –> Output = -1
• Input -23,09 –> Output = 23,09
• Input 0 –> Output = 0 ## SmartRound Functoid

Use the SmartRound Functoid to return any number (int or double) rounded up or down to any decimal place, specified by the second parameter of this functoid.

### Parameters

The functoid takes two mandatory input parameters:

1. Parameter 1: Number to be rounded (double or int)
2. Parameter 2: Number to decimals places

The output of the functoid will be the input number rounded up or down to the specified decimal places. For example:

• Input 23 rounded to 2 –> Output = 23,00
• Input 24,005900 rounded to 3 –> Output = 24,006 ## BizTalk Mapper Extensions UtilityPack: Project Description

BizTalk Mapper Extensions UtilityPack is a set of libraries with several useful functoids to include and use it in a map, which will provide an extension of BizTalk Mapper capabilities. BizTalk Mapper Extensions UtilityPack 