float-ing through time

πŸ“† Created on February 8, 2024. πŸ”– programmingunity3d

I was curious this morning about Unitys Time.realTimeSinceStartup, specifically how much time it would take to overflow the value. Reading the Unity docs says:

The real time in seconds since the game started (Read Only).

Ok. Well that's not very helpful. It's a float so I guess first, I'll check what the max value for a float is in c#. Microsoft docs say its 3.40282347E+38 ... that seems incredibly big. But, how big?

Well, let's start doing some quick and dirty math. $maxValue / 60 will get us the minutes.

3.40282347E+38 / 60 = 5.6713724e+36

Oh. Uhm, well shit, ok that's still huge. Fine, how about days?

3.40282347E+38 / 60 / 60 / 24 = 3.9384531e+33

Uhmmmm ok. I'm getting scared. How about centuries?

3.40282347E+38 / 60 / 60 / 24 / 365 / 100 = 1.0790282e+29

Oh, ok well that's 107,902,820,000,000,000,000,000,000,000 CENTURIES...in seconds... So yeah, that value would overflow if someone left the game running for one hundred seven octillion, nine hundred two septillion, eight hundred twenty sextillion centuries.

via GIPHY

Previous Code Recipe: CustomAssertions Next Test Structuring in C#