116 lines
2.6 KiB
Markdown
116 lines
2.6 KiB
Markdown
---
|
|
title: math.mod() function
|
|
description: >
|
|
`math.mod()` returns a floating-point remainder of `x/y`.
|
|
menu:
|
|
flux_v0_ref:
|
|
name: math.mod
|
|
parent: math
|
|
identifier: math/mod
|
|
weight: 101
|
|
---
|
|
|
|
<!------------------------------------------------------------------------------
|
|
|
|
IMPORTANT: This page was generated from comments in the Flux source code. Any
|
|
edits made directly to this page will be overwritten the next time the
|
|
documentation is generated.
|
|
|
|
To make updates to this documentation, update the function comments above the
|
|
function definition in the Flux source code:
|
|
|
|
https://github.com/influxdata/flux/blob/master/stdlib/math/math.flux#L1651-L1651
|
|
|
|
Contributing to Flux: https://github.com/influxdata/flux#contributing
|
|
Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md
|
|
|
|
------------------------------------------------------------------------------->
|
|
|
|
`math.mod()` returns a floating-point remainder of `x/y`.
|
|
|
|
The magnitude of the result is less than `y` and its sign agrees
|
|
with that of `x`.
|
|
|
|
**Note**: `math.mod()` performs the same operation as the modulo operator (`%`).
|
|
For example: `4.56 % 1.23`
|
|
|
|
##### Function type signature
|
|
|
|
```js
|
|
(x: float, y: float) => float
|
|
```
|
|
|
|
{{% caption %}}
|
|
For more information, see [Function type signatures](/flux/v0/function-type-signatures/).
|
|
{{% /caption %}}
|
|
|
|
## Parameters
|
|
|
|
### x
|
|
({{< req >}})
|
|
x-value to use in the operation.
|
|
|
|
|
|
|
|
### y
|
|
({{< req >}})
|
|
y-value to use in the operation.
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
- [Return the modulo of two values](#return-the-modulo-of-two-values)
|
|
- [Use math.mod in map](#use-mathmod-in-map)
|
|
|
|
### Return the modulo of two values
|
|
|
|
```js
|
|
import "math"
|
|
|
|
math.mod(x: 4.56, y: 1.23)// 0.8699999999999997
|
|
|
|
|
|
```
|
|
|
|
|
|
### Use math.mod in map
|
|
|
|
```js
|
|
import "math"
|
|
|
|
data
|
|
|> map(fn: (r) => ({_time: r._time, _value: math.mod(x: r.t1, y: r.t2)}))
|
|
|
|
```
|
|
|
|
{{< expand-wrapper >}}
|
|
{{% expand "View example input and output" %}}
|
|
|
|
#### Input data
|
|
|
|
| _time | t1 | t2 |
|
|
| -------------------- | ----- | ----- |
|
|
| 2021-01-01T00:00:00Z | -2.18 | 19.85 |
|
|
| 2021-01-01T00:00:10Z | 10.92 | 4.97 |
|
|
| 2021-01-01T00:00:20Z | 7.35 | -3.75 |
|
|
| 2021-01-01T00:00:30Z | 17.53 | 19.77 |
|
|
| 2021-01-01T00:00:40Z | 15.23 | 13.86 |
|
|
| 2021-01-01T00:00:50Z | 4.43 | 1.86 |
|
|
|
|
|
|
#### Output data
|
|
|
|
| _time | _value |
|
|
| -------------------- | ------------------ |
|
|
| 2021-01-01T00:00:00Z | -2.18 |
|
|
| 2021-01-01T00:00:10Z | 0.9800000000000004 |
|
|
| 2021-01-01T00:00:20Z | 3.5999999999999996 |
|
|
| 2021-01-01T00:00:30Z | 17.53 |
|
|
| 2021-01-01T00:00:40Z | 1.370000000000001 |
|
|
| 2021-01-01T00:00:50Z | 0.7099999999999995 |
|
|
|
|
{{% /expand %}}
|
|
{{< /expand-wrapper >}}
|