Mathf.Min/Max/Clamp need long/short/byte support

Bandwidth optimizations are very important for networking projects, especially now since UNET is getting bigger and bigger. Often times we need ‘short’ or ‘byte’ instead of ‘int’.

When will we see Mathf functions for long, short, byte, etc.? Of course, they can be implemented manually. But it’s not very elegant to use ‘Mathf.Min’ for int and then ‘MyUnityEnhancements.Min’ for short and long. It makes the code much harder to read, especially for beginners or for people buying Asset Store projects.

Could any Unity developer perhaps take a few minutes to add support for those other data types, at least for Mathf.Min/Max/Clamp?

System.Math will give you Min/Max.

3 Likes

Mathf is specifically for floating point operations, the system already has non floating point versions in System.Math.

While the name certainly suggests so, the Mathf class does provide a number of overloads specifically for int.

But you’re right that the system namespace already provides some missing operations.

I do prefer to use one family of math routines when possible so I agree it would be nice to have some more data types catered for in Mathf.

Thank you guys, that makes sense!

Mathf.Min still doesn’t support Long.

Long is supported by System.Math.Min:

https://learn.microsoft.com/en-us/dotnet/api/system.math.min?view=net-7.0#system-math-min(system-int64-system-int64)

3 Likes

This thread ended in 2016, when everything needed to be said, was said. Did you read the other replies? The Math library in C# has plenty of support for Int64, the Mathf library in Unity is meant to cover fIoat math additions.

https://learn.microsoft.com/en-us/dotnet/api/system.math?view=net-7.0

2 Likes