---
source_url: https://www.pubnub.com/docs/serverless/functions/functions-apis/advanced-math-module
title: Advanced Math Module
updated_at: 2026-06-29T08:08:11.868Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Advanced Math Module

The `advanced_math` module is a PubNub Functions utility for distance calculations.

## Distance calculation methods

Use `getDistance()` to return the distance, in miles, between two latitude/longitude coordinates.

Usage: `getDistance(lat1, lon1, lat2, lon2)` where:

* `lat1`: latitude of the first point
* `lon1`: longitude of the first point
* `lat2`: latitude of the second point
* `lon2`: longitude of the second point

```javascript
const advancedMath = require('advanced_math');
const distanceInMiles = advancedMath.getDistance(43.7001100, -79.4163000, 37.7749300, -122.4194200);
```

## Degrees to radians

Use `deg2rad()` to convert degrees to radians.

Usage: `deg2rad(deg)` where:

* `deg`: degrees to convert

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

:::note Functions support
Functions provides a rich set of tools, and this documentation may not cover every situation. If you need help with a case not covered here, please contact [PubNub Support](https://www.pubnub.com/docs/mailto:support@pubnub.com).
:::