Search Issue Tracker

Fixed in 2022.2.X

Duplicate in 2020.3.X, 2021.3.X

Votes

0

Found in

2019.4

2020.3

2021.1.23f1

2021.2

2022.1

Issue ID

1372997

Regression

No

Unnecessary cast to float when calling Mathf.Abs

Scripting

-

The return type of Math.Abs is float, so explicit cast to float in the return statement of Mathf.Abs is unnecessary and leads to increase execution time

Mathf.Abs:
public static float Abs(float f) { return (float)Math.Abs(f); }
Custom Abs method:
float Abs (float input) { return Math.Abs(input); }
Math.Abs:
public static float Abs (float value);

Steps to reproduce:
1. Open the attached "1372997-sample" project
2. Enter Play mode
3. Observe the Console

Expected result: executing time of Mathf.Abs is taking the approximately same amount of time as the custom Abs method
Actual result: executing Mathf.Abs takes noticeably more time

  1. Resolution Note (fix version 2022.2):

    Fixed in 2022.2.0a1

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.