---
title: fmodsafe
product: Unity Editor
version: '7000.0'
latest_version: '7000.0'
status: This page documents version 7000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/mathematics/math/fmodsafe
latest_url: https://docs.unity.com/en-us/engine/7000.0/script-reference/unity/mathematics/math/fmodsafe.md
last_updated: 2026-11-20
generated_at: 2026-11-25T22:12:23.402Z
locale: en-us
---

# fmodsafe

> Returns the floating point remainder of x/y, or zero if y is zero.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Mathematics](/engine/7000.0/script-reference/unity/mathematics.md)
* **Assembly:** UnityEngine.MathematicsModule

## fmodsafe(float, float)

Returns the floating point remainder of x/y, or zero if y is zero.

```csharp
public static float fmodsafe(float x, float y)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The dividend in x/y.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The divisor in x/y.

### Returns

| Type                                                          | Description                    |
| ------------------------------------------------------------- | ------------------------------ |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor returns zero instead of NaN.

## fmodsafe(float2, float2)

Returns the componentwise floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static float2 fmodsafe(float2 x, float2 y)
```

### Parameters

**** (\[float2]\(/engine/7000.0/script-reference/unity/mathematics/float2)): The dividend in x/y.**** (\[float2]\(/engine/7000.0/script-reference/unity/mathematics/float2)): The divisor in x/y.

### Returns

| Type                                                                  | Description                                  |
| --------------------------------------------------------------------- | -------------------------------------------- |
| [float2](/engine/7000.0/script-reference/unity/mathematics/float2.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.

## fmodsafe(float3, float3)

Returns the componentwise floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static float3 fmodsafe(float3 x, float3 y)
```

### Parameters

**** (\[float3]\(/engine/7000.0/script-reference/unity/mathematics/float3)): The dividend in x/y.**** (\[float3]\(/engine/7000.0/script-reference/unity/mathematics/float3)): The divisor in x/y.

### Returns

| Type                                                                  | Description                                  |
| --------------------------------------------------------------------- | -------------------------------------------- |
| [float3](/engine/7000.0/script-reference/unity/mathematics/float3.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.

## fmodsafe(float4, float4)

Returns the componentwise floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static float4 fmodsafe(float4 x, float4 y)
```

### Parameters

**** (\[float4]\(/engine/7000.0/script-reference/unity/mathematics/float4)): The dividend in x/y.**** (\[float4]\(/engine/7000.0/script-reference/unity/mathematics/float4)): The divisor in x/y.

### Returns

| Type                                                                  | Description                                  |
| --------------------------------------------------------------------- | -------------------------------------------- |
| [float4](/engine/7000.0/script-reference/unity/mathematics/float4.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.

## fmodsafe(double, double)

Returns the double precision floating point remainder of x/y, or zero if y is zero.

```csharp
public static double fmodsafe(double x, double y)
```

### Parameters

**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): The dividend in x/y.**** (\[double]\(https\://learn.microsoft.com/dotnet/api/system.double)): The divisor in x/y.

### Returns

| Type                                                           | Description                    |
| -------------------------------------------------------------- | ------------------------------ |
| [double](https://learn.microsoft.com/dotnet/api/system.double) | The remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor returns zero instead of NaN.

## fmodsafe(double2, double2)

Returns the componentwise double precision floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static double2 fmodsafe(double2 x, double2 y)
```

### Parameters

**** (\[double2]\(/engine/7000.0/script-reference/unity/mathematics/double2)): The dividend in x/y.**** (\[double2]\(/engine/7000.0/script-reference/unity/mathematics/double2)): The divisor in x/y.

### Returns

| Type                                                                    | Description                                  |
| ----------------------------------------------------------------------- | -------------------------------------------- |
| [double2](/engine/7000.0/script-reference/unity/mathematics/double2.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.

## fmodsafe(double3, double3)

Returns the componentwise double precision floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static double3 fmodsafe(double3 x, double3 y)
```

### Parameters

**** (\[double3]\(/engine/7000.0/script-reference/unity/mathematics/double3)): The dividend in x/y.**** (\[double3]\(/engine/7000.0/script-reference/unity/mathematics/double3)): The divisor in x/y.

### Returns

| Type                                                                    | Description                                  |
| ----------------------------------------------------------------------- | -------------------------------------------- |
| [double3](/engine/7000.0/script-reference/unity/mathematics/double3.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.

## fmodsafe(double4, double4)

Returns the componentwise double precision floating point remainder of x/y, or zero for each component where y is zero.

```csharp
public static double4 fmodsafe(double4 x, double4 y)
```

### Parameters

**** (\[double4]\(/engine/7000.0/script-reference/unity/mathematics/double4)): The dividend in x/y.**** (\[double4]\(/engine/7000.0/script-reference/unity/mathematics/double4)): The divisor in x/y.

### Returns

| Type                                                                    | Description                                  |
| ----------------------------------------------------------------------- | -------------------------------------------- |
| [double4](/engine/7000.0/script-reference/unity/mathematics/double4.md) | The componentwise remainder of x/y, or zero. |

### Remarks

Unlike [math.fmod](/engine/7000.0/script-reference/unity/mathematics/math/fmod.md), a zero or NaN divisor component returns zero instead of NaN.
