A utility module that provides mathematical functions.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

To use this module, you must import it to your DataWeave code, for example, by adding the line import * from dw::util::Math to the header of your DataWeave script.

Functions

acos

acos(angle: Number): Number | NaN

Returns an arc cosine value that can range from 0.0 through pi.

If the absolute value of the input is greater than 1, the result is null.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number to convert into it arc cosine value.

Example

This example shows how acos behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
11
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "acos0": acos(0),
  "acos13": acos(0.13),
  "acos-1": acos(-1),
  "acos1": acos(1),
  "acos1.1": acos(1.1)
}
Output
1
2
3
4
5
6
7
{
   "acos0": 1.5707963267948966,
   "acos13": 1.440427347091751,
   "acos-1": 3.141592653589793,
   "acos1": 0.0,
   "acos1.1": null
 }

asin

asin(angle: Number): Number

Returns an arc sine value that can range from -pi/2 through pi/2.

If the absolute value of the input is greater than 1, the result is null.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number to convert into its arc sine value.

Example

This example shows how asin behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "asin0": asin(0),
  "asin13": asin(0.13),
  "asin-1": asin(-1),
  "asin1.1": asin(1.1)
}
Output
1
2
3
4
5
6
{
   "asin0": 0.0,
   "asin13": 0.1303689797031455,
   "asin-1": -1.5707963267948966,
   "asin1.1": null
 }

atan

atan(angle: Number): Number

Returns an arc tangent value that can range from -pi/2 through pi/2.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number to convert into its arc tangent value.

Example

This example shows how atan behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "atan0":  atan(0),
  "atan13": atan(0.13),
  "atan-1": atan(-1)
}
Output
1
2
3
4
5
{
   "atan0": 0.0,
   "atan13": 0.12927500404814307,
   "atan-1": -0.7853981633974483
}

cos

cos(angle: Number): Number

Returns the trigonometric cosine of an angle from a given number of radians.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number of radians in an angle.

Example

This example shows how cos behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "cos0": cos(0),
  "cos13": cos(0.13),
  "cos-1": cos(-1)
}
Output
1
2
3
4
5
{
  "cos0": 1.0,
  "cos13": 0.9915618937147881,
  "cos-1": 0.5403023058681398
}

log10

log10(a: Number): Number | NaN

Returns the logarithm base 10 of a number.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

a

A Number value that serves as input to the function.

Example

This example shows how log10 behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "log1010": log10(10),
  "log1013": log10(0.13),
  "log10-20": log10(-20)
}
Output
1
2
3
4
5
 {
    "log1010": 1.0,
    "log1013": -0.8860566476931632,
    "log10-20": null
 }

logn

logn(a: Number): Number | NaN

Returns the natural logarithm (base e) of a number.

If the input value is less than or equal to zero, the result is NaN (or null).

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

a

Number to convert into its natural logarithm.

Example

This example shows how logn behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
   "logn10":  logn(10),
   "logn13": logn(0.13),
   "logn-20": logn(-20)
}
Output
1
2
3
4
5
{
   "logn10": 2.302585092994046,
   "logn13": -2.0402208285265546,
   "logn-20": null
}

sin

sin(angle: Number): Number

Returns the trigonometric sine of an angle from a given number of radians.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number of radians in an angle.

Example

This example shows how sin behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "sin0": sin(0),
  "sin13": sin(0.13),
  "sin-1": sin(-1)
}
Output
1
2
3
4
5
{
  "sin0": 0.0,
  "sin13": 0.12963414261969486,
  "sin-1": -0.8414709848078965
}

tan

tan(angle: Number): Number

Returns the trigonometric tangent of an angle from a given number of radians.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angle

Number of radians in an angle.

Example

This example shows how tan behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
   "tan0": tan(0),
   "tan13": tan(0.13),
   "tan-1": tan(-1)
}
Output
1
2
3
4
5
{
   "tan0": 0.0,
   "tan13": 0.13073731800446006,
   "tan-1": -1.5574077246549023
 }

toDegrees

toDegrees(angrad: Number): Number

Converts an angle measured in radians to an approximately equivalent number of degrees.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angrad

Number of radians to convert to degrees.

Example

This example shows how toDegrees behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "toDegrees0.17":  toDegrees(0.174),
  "toDegrees0": toDegrees(0),
  "toDegrees-20": toDegrees(-0.20)
}
Output
1
2
3
4
5
{
   "toDegrees0.17": 9.969465635276323832571267395889251,
   "toDegrees0": 0E+19,
   "toDegrees-20": -11.45915590261646417536927286883822
 }

toRadians

toRadians(angdeg: Number): Number

Converts a given number of degrees in an angle to an approximately equivalent number of radians.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

Parameters
Name Description

angdeg

Number of degrees to convert into radians.

Example

This example shows how toRadians behaves with different inputs.

Source
1
2
3
4
5
6
7
8
9
%dw 2.0
import * from dw::util::Math
output application/json
---
{
  "toRadians10":  toRadians(10),
  "toRadians013": toRadians(0.13),
  "toRadians-20": toRadians(-20)
}
Output
1
2
3
4
5
6
{
   "toRadians10": 0.1745329251994329576922222222222222,
   "toRadians013": 0.002268928027592628449998888888888889,
   "toRadians-20": -0.3490658503988659153844444444444444
 }

Variables

E

Variable E sets the value of mathematical constant e, the base of natural logarithms.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.

PI

Variable PI sets the value of constant value pi, the ratio of the circumference of a circle to its diameter.

Introduced in DataWeave 2.4.0. Supported by Mule 4.4.0 and later.