---
source_url: https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/advanced-math
title: advanced_math
updated_at: 2026-09-30T07:20:08.000Z
---

# advanced_math

## Documentation index

To discover more PubNub resources:

1. Fetch [PubNub's llms.txt](https://www.pubnub.com/llms-full.txt) for a list of available pages in Markdown format.
2. Identify relevant URLs from that index.
3. Fetch the target pages.

Do not assume a path exists, always check the index first.

The `advanced_math` built-in module is available only inside a PubNub Function. It calculates distances and converts degrees to radians.

```javascript
const advancedMath = require('advanced_math');
```

## getDistance

`getDistance(lat1, lon1, lat2, lon2)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| lat1 | Number | Yes |  | Latitude of the first point. |
| lon1 | Number | Yes |  | Longitude of the first point. |
| lat2 | Number | Yes |  | Latitude of the second point. |
| lon2 | Number | Yes |  | Longitude of the second point. |

Returns: the distance between the two points, in miles.

```javascript
const advancedMath = require('advanced_math');
const distanceInMiles = advancedMath.getDistance(43.70011, -79.4163, 37.77493, -122.41942);
```

## deg2rad

`deg2rad(deg)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| deg | Number | Yes |  | Degrees to convert. |

Returns: `deg` converted to radians.

```javascript
const advancedMath = require('advanced_math');
const radians = advancedMath.deg2rad(30);
```

## Related reference

* [Modules and libraries](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/overview.md). Every built-in module available inside a Function.

Last updated at: 2026-09-30T07:20:08.000Z
