public static volatile float FloatMinNormal = 1.17549435E-38f;
public static volatile float FloatMinDenormal = Single.Epsilon;
Is it correct to mark Epsilon as volatile? This keyword implies a high frequency of changes to the value. In reality, this static value never changes beyond initial creation. By marking this variable volatile it prevents the register/memory from residing in the CPU cache. Would removing the volatile keyword here improve performance of Mathf operations which use Epsilon?
Looks like there was this comment above that got lost 4.5 years ago:
// Note that the following needs to be volatile in order to prevent
// the condition in IsFlushToZeroEnabled being optimized out
C# compiler can apparently optimize it out, but you don’t actually know what the value will be there at runtime because it depends on the CPU you’re running on.
Thanks @Tautvydas-Zilys ! I didn’t read the code right – I now see that value is eventually carried into Epsilon, which is not marked volatile. I’m sure it is challenging to maintain such a complex and storied code base. Thank you for your insights!
// A tiny floating point value (RO).
public static readonly float Epsilon =
UnityEngineInternal.MathfInternal.IsFlushToZeroEnabled ? UnityEngineInternal.MathfInternal.FloatMinNormal
: UnityEngineInternal.MathfInternal.FloatMinDenorma