Unity vs. Floating Point

(aras-p.info)

40 points | by ibobev 3 days ago ago

10 comments

  • corysama 22 minutes ago

    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!

  • Zarathruster an hour ago

    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.

  • koolala 3 hours ago

    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.

    • taeric 2 hours ago

      I wish there was more explicit support for fixed point decimal out there.

      • bee_rider 26 minutes ago

        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…

        • taeric 6 minutes ago

          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.

      • koolala 2 hours ago

        Speed wise no hardware can do it though.

        • taeric 21 minutes ago

          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.

    • adgjlsfhk1 an hour ago

      What do you mean by Array Language? Would Julia qualify here?

      • koolala 34 minutes ago

        I was thinking like APL, all the open ones are float64 based.