# normalizesafe

> Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

## Definition

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

## normalizesafe(float2, float2)

Returns a safe normalized version of the float2 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static float2 normalizesafe(float2 x, float2 defaultvalue = default)
```

### Parameters

**** (\[float2]\(/engine/6000.5/script-reference/unity/mathematics/float2)): Vector to normalize.**** (\[float2]\(/engine/6000.5/script-reference/unity/mathematics/float2)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                  | Description                                                                        |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [float2](/engine/6000.5/script-reference/unity/mathematics/float2.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(float3, float3)

Returns a safe normalized version of the float3 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static float3 normalizesafe(float3 x, float3 defaultvalue = default)
```

### Parameters

**** (\[float3]\(/engine/6000.5/script-reference/unity/mathematics/float3)): Vector to normalize.**** (\[float3]\(/engine/6000.5/script-reference/unity/mathematics/float3)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                  | Description                                                                        |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [float3](/engine/6000.5/script-reference/unity/mathematics/float3.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(float4, float4)

Returns a safe normalized version of the float4 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static float4 normalizesafe(float4 x, float4 defaultvalue = default)
```

### Parameters

**** (\[float4]\(/engine/6000.5/script-reference/unity/mathematics/float4)): Vector to normalize.**** (\[float4]\(/engine/6000.5/script-reference/unity/mathematics/float4)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                  | Description                                                                        |
| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [float4](/engine/6000.5/script-reference/unity/mathematics/float4.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(double2, double2)

Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static double2 normalizesafe(double2 x, double2 defaultvalue = default)
```

### Parameters

**** (\[double2]\(/engine/6000.5/script-reference/unity/mathematics/double2)): Vector to normalize.**** (\[double2]\(/engine/6000.5/script-reference/unity/mathematics/double2)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                    | Description                                                                        |
| ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [double2](/engine/6000.5/script-reference/unity/mathematics/double2.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(double3, double3)

Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static double3 normalizesafe(double3 x, double3 defaultvalue = default)
```

### Parameters

**** (\[double3]\(/engine/6000.5/script-reference/unity/mathematics/double3)): Vector to normalize.**** (\[double3]\(/engine/6000.5/script-reference/unity/mathematics/double3)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                    | Description                                                                        |
| ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [double3](/engine/6000.5/script-reference/unity/mathematics/double3.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(double4, double4)

Returns a safe normalized version of the double4 vector x by scaling it by 1 / length(x). Returns the given default value when 1 / length(x) does not produce a finite number.

```csharp
public static double4 normalizesafe(double4 x, double4 defaultvalue = default)
```

### Parameters

**** (\[double4]\(/engine/6000.5/script-reference/unity/mathematics/double4)): Vector to normalize.**** (\[double4]\(/engine/6000.5/script-reference/unity/mathematics/double4)): Vector to return if normalized vector is not finite.

### Returns

| Type                                                                    | Description                                                                        |
| ----------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [double4](/engine/6000.5/script-reference/unity/mathematics/double4.md) | The normalized vector or the default value if the normalized vector is not finite. |

## normalizesafe(quaternion)

Returns a safe normalized version of the q by scaling it by 1 / length(q). Returns the identity when 1 / length(q) does not produce a finite number.

```csharp
public static quaternion normalizesafe(quaternion q)
```

### Parameters

**** (\[quaternion]\(/engine/6000.5/script-reference/unity/mathematics/quaternion)): The quaternion to normalize.

### Returns

| Type                                                                          | Description                                           |
| ----------------------------------------------------------------------------- | ----------------------------------------------------- |
| [quaternion](/engine/6000.5/script-reference/unity/mathematics/quaternion.md) | The normalized quaternion or the identity quaternion. |

## normalizesafe(quaternion, quaternion)

Returns a safe normalized version of the q by scaling it by 1 / length(q). Returns the given default value when 1 / length(q) does not produce a finite number.

```csharp
public static quaternion normalizesafe(quaternion q, quaternion defaultvalue)
```

### Parameters

**** (\[quaternion]\(/engine/6000.5/script-reference/unity/mathematics/quaternion)): The quaternion to normalize.**** (\[quaternion]\(/engine/6000.5/script-reference/unity/mathematics/quaternion)): The default value.

### Returns

| Type                                                                          | Description                                     |
| ----------------------------------------------------------------------------- | ----------------------------------------------- |
| [quaternion](/engine/6000.5/script-reference/unity/mathematics/quaternion.md) | The normalized quaternion or the default value. |
