> The operation is finished when the progress float reaches 1.0 and isDone is called. If you set allowSceneActivation to false, progress is halted at 0.9 until it is set to true.
So, I needed to have my UI do other stuff until both this and something else was ready. Obvious thing to do would be to check this for "AsyncOperation.progress >= 0.9" and also check the other thing. Right?
Except AsyncOperation.progress is a float, 0.9 is a double and 0.9f < 0.9. Progress is not halted at 0.9. It never reaches 0.9. It's halted at 0.9f! Just a few million ulps short!
1) Why would you use floating point instead of fixed point or other fractional representation (uh, percent?) for this sort of thing?
2) Why would you design an interface that's specifically set up to make progress bars stall at 90%? This is insanely user hostile -- there are great UI patterns for expressing indeterminate progress when your progress is indeterminate!
3) Why in the example would you prompt user interaction at 90%? (I'll give them credit for at least comparing to 0.9f instead of 0.9 here.) What user expects a prompt to appear before progress is complete?
>Official Mono releases have switched to do that since then, but (I think) for backwards compatibility reasons Unity never enabled that functionality and kept everything at double precision so far.
Probably because Unity uses ancient Mono fork. And that apparently started because they didn't renew their non-copyleft license with Xamarin.
Unity used to be on ancient version of Mono before year 2017. Then until 2019 the option to use “up to date” version was optional. Since 2019 it has been on more or less current Mono version (Mono itself stopped getting any serious updates around 2020).
Interesting. When I first got started with Unity I found really buggy behavior if you do any kind of physics calculations near world origin (0, 0, 0). It has a weird gravity well effect if you get too near it. I never found a satisfactory explanation for it but maybe this is it.
If you mean built-in Unity physics, then unlikely. All built-in physics stuff (either 3D physics which is PhysX, or 2D physics which is Box2D) are done entirely in C++ code and are unaffected by Mono float<->double shenanigans.
Do you mean fixed point using integers, or actually decimal (base-10)? My gut would be to use fixed-point integers with a power of two in the denominator.
On the other hand, I’m not sure if modern compilers even bother converting division/multiplications by powers of two to shifts these days, so maybe it isn’t worth it…
Compilers will convert mul/div to shifts, if they notice one of the operands is a power of 2. I would have included a link to an example on compiler explorer (https://godbolt.org/) but the source editor didn't work on my Pinephone for some reason..
Fair that relying on decimal is an interesting choice. My gut is that it would help with a lot of reasoning for folks.
This comes up all of the time with stuff like lat/lng values. People are convinced you have to use doubles because of the inaccuracy of floats. Completely skipping over the fact that you could have fixed point accuracy to 6 decimal digits with the same number of bits as a float. You just reduce your max/min value that you can represent. Which, for lat/lng, you are already heavily bounded.
I think it is fair to argue that basic libraries don't support trig on common fixed point sizes. But that is ultimately my lament. Floats are amazing for what they need to do. For what many people need, though, it feels overkill because it is overkill.
> This comes up all of the time with stuff like lat/lng values. People are convinced you have to use doubles because of the inaccuracy of floats.
Using any floating point representation for lat/long makes no sense at all to me. Floating point is designed for representing values where expected error scales with magnitude, not for values where error is constant with magnitude; the latter requires fixed point. I truly don't understand why someone would optimize their position representation for maximum accuracy off the coast of Africa, instead of having it uniform across the world.
Depends how you measure. The choice of floating point lat/long is very favorable for people in the area of Null Island, and while the population there nearly zero, the population density is either NaN or infinite, depending on how you handle your divide-by-zeros. I can certainly see optimizing your implementation for an infinite-population-density-area region...
This depends entirely on the sizes needed. For a surprising number of things people would use fixed point for, I would be surprised if you couldn't get good speed with surprisingly little effort.
If you don't have to do trig, I'd be surprised if you aren't faster by default, oddly. Indeed, if you are just adding and subtracting, it is just a number. If you are doing multiplication, it is a multiply and shift. So long as you don't try and support massive numbers of different fixed sizes, that shift is almost certainly still cheaper than float hardware. (Indeed, a lot of multiplications wouldn't even need the shift...)
Again, I do not mean this as a criticism of floats. For simulations and for numbers where you do have to support completely arbitrary values, there is a reason floats are a thing.
An integer add, sub, or shift is 1 cycle of latency; integer mul is generally 3 cycles; integer div is lol-that-is-slow. Floating-point adds, subs, muls, and fmas are generally 4 cycles, with div being lol-that-is-slow (but generally faster than integer division because your divisor and dividend have fewer bits).
So fixed-point addition and subtraction are definitely faster, multiplication is a wash if you're doing binary-based fixed point (but slower if you're doing decimal-based fixed point), and fixed-point division is definitely slower than floating-point division.
Kudos on providing the numbers. I wasn't confident in the numbers that I remembered and with how pipelined everything is, I didn't know how much to lean on them. Not exactly my standard workflow to care about this level of speed.
My gut would still be that it is typically a wash for most everyone as far as speeds go? If default libraries supported it more directly, I would think it would largely be a win for a lot of reasoning. In particular, silly stuff like 1e32 + 1e1 would not be nearly as surprising to most people. And the entire class of bugs around stuff like doing something until it reaches 0.9 would almost certainly go away if we guaranteed precision to a set number decimal places.
Alas, default libraries do not support this, though. So the above is admittedly wishful thinking on my end. And I could as easily describe a world where people insist on arbitrary numbers of fixed point values and how that would be its own set of landmines.
Only tangentially related. But, I still have not forgiven Unity for the floating point footgun in https://docs.unity3d.com/6000.4/Documentation/ScriptReferenc...
> The operation is finished when the progress float reaches 1.0 and isDone is called. If you set allowSceneActivation to false, progress is halted at 0.9 until it is set to true.
So, I needed to have my UI do other stuff until both this and something else was ready. Obvious thing to do would be to check this for "AsyncOperation.progress >= 0.9" and also check the other thing. Right?
Except AsyncOperation.progress is a float, 0.9 is a double and 0.9f < 0.9. Progress is not halted at 0.9. It never reaches 0.9. It's halted at 0.9f! Just a few million ulps short!
This is insane in so many different ways.
1) Why would you use floating point instead of fixed point or other fractional representation (uh, percent?) for this sort of thing?
2) Why would you design an interface that's specifically set up to make progress bars stall at 90%? This is insanely user hostile -- there are great UI patterns for expressing indeterminate progress when your progress is indeterminate!
3) Why in the example would you prompt user interaction at 90%? (I'll give them credit for at least comparing to 0.9f instead of 0.9 here.) What user expects a prompt to appear before progress is complete?
trigger warning, lol
>Official Mono releases have switched to do that since then, but (I think) for backwards compatibility reasons Unity never enabled that functionality and kept everything at double precision so far.
Probably because Unity uses ancient Mono fork. And that apparently started because they didn't renew their non-copyleft license with Xamarin.
That is not actually true.
Unity used to be on ancient version of Mono before year 2017. Then until 2019 the option to use “up to date” version was optional. Since 2019 it has been on more or less current Mono version (Mono itself stopped getting any serious updates around 2020).
Interesting. When I first got started with Unity I found really buggy behavior if you do any kind of physics calculations near world origin (0, 0, 0). It has a weird gravity well effect if you get too near it. I never found a satisfactory explanation for it but maybe this is it.
If you mean built-in Unity physics, then unlikely. All built-in physics stuff (either 3D physics which is PhysX, or 2D physics which is Box2D) are done entirely in C++ code and are unaffected by Mono float<->double shenanigans.
I wish JavaScript or any open-source Array Language could do Single-precision Floats. It's awesome they were able to show the assembly breakdown.
I wish there was more explicit support for fixed point decimal out there.
Do you mean fixed point using integers, or actually decimal (base-10)? My gut would be to use fixed-point integers with a power of two in the denominator.
On the other hand, I’m not sure if modern compilers even bother converting division/multiplications by powers of two to shifts these days, so maybe it isn’t worth it…
Compilers will convert mul/div to shifts, if they notice one of the operands is a power of 2. I would have included a link to an example on compiler explorer (https://godbolt.org/) but the source editor didn't work on my Pinephone for some reason..
Fair that relying on decimal is an interesting choice. My gut is that it would help with a lot of reasoning for folks.
This comes up all of the time with stuff like lat/lng values. People are convinced you have to use doubles because of the inaccuracy of floats. Completely skipping over the fact that you could have fixed point accuracy to 6 decimal digits with the same number of bits as a float. You just reduce your max/min value that you can represent. Which, for lat/lng, you are already heavily bounded.
I think it is fair to argue that basic libraries don't support trig on common fixed point sizes. But that is ultimately my lament. Floats are amazing for what they need to do. For what many people need, though, it feels overkill because it is overkill.
> This comes up all of the time with stuff like lat/lng values. People are convinced you have to use doubles because of the inaccuracy of floats.
Using any floating point representation for lat/long makes no sense at all to me. Floating point is designed for representing values where expected error scales with magnitude, not for values where error is constant with magnitude; the latter requires fixed point. I truly don't understand why someone would optimize their position representation for maximum accuracy off the coast of Africa, instead of having it uniform across the world.
Agreed. But I'm assuming we are in the minority on this one? Bad assumption?
Depends how you measure. The choice of floating point lat/long is very favorable for people in the area of Null Island, and while the population there nearly zero, the population density is either NaN or infinite, depending on how you handle your divide-by-zeros. I can certainly see optimizing your implementation for an infinite-population-density-area region...
Speed wise no hardware can do it though.
This depends entirely on the sizes needed. For a surprising number of things people would use fixed point for, I would be surprised if you couldn't get good speed with surprisingly little effort.
I would be surprised if you could get even one third of performance of floats. So why bother?
If you don't have to do trig, I'd be surprised if you aren't faster by default, oddly. Indeed, if you are just adding and subtracting, it is just a number. If you are doing multiplication, it is a multiply and shift. So long as you don't try and support massive numbers of different fixed sizes, that shift is almost certainly still cheaper than float hardware. (Indeed, a lot of multiplications wouldn't even need the shift...)
Again, I do not mean this as a criticism of floats. For simulations and for numbers where you do have to support completely arbitrary values, there is a reason floats are a thing.
An integer add, sub, or shift is 1 cycle of latency; integer mul is generally 3 cycles; integer div is lol-that-is-slow. Floating-point adds, subs, muls, and fmas are generally 4 cycles, with div being lol-that-is-slow (but generally faster than integer division because your divisor and dividend have fewer bits).
So fixed-point addition and subtraction are definitely faster, multiplication is a wash if you're doing binary-based fixed point (but slower if you're doing decimal-based fixed point), and fixed-point division is definitely slower than floating-point division.
Kudos on providing the numbers. I wasn't confident in the numbers that I remembered and with how pipelined everything is, I didn't know how much to lean on them. Not exactly my standard workflow to care about this level of speed.
My gut would still be that it is typically a wash for most everyone as far as speeds go? If default libraries supported it more directly, I would think it would largely be a win for a lot of reasoning. In particular, silly stuff like 1e32 + 1e1 would not be nearly as surprising to most people. And the entire class of bugs around stuff like doing something until it reaches 0.9 would almost certainly go away if we guaranteed precision to a set number decimal places.
Alas, default libraries do not support this, though. So the above is admittedly wishful thinking on my end. And I could as easily describe a world where people insist on arbitrary numbers of fixed point values and how that would be its own set of landmines.
What do you mean by Array Language? Would Julia qualify here?
I was thinking like APL, all the open ones are float64 based.