1. 17
  1.  

  2. 1

    After reading, I have to ask: what about a “reducing” technique? You could average the numbers in equal-sized chunks, then average those averages. Then you could even chunk the chunks’ averages and repeat the process as many levels down as you want to. And then the chunks could be as small as 2 each. I guess this still assumes that the largest number in the original list is less than or equal to the maximum floating-point value, but other than that you stay roughly in the same space of precision as the original data.

    1. 2

      So how do you compute the average of two maximum float values? Or just one? The instant you add anything positive to a max float it becomes inf.

      1. 1

        aren’t doubles there for that?

        1. 1

          There’s a max value for a double: 1.797693134862316e+308 How do you find the average of 1.797693134862316e+308 and 1.797693134862314e+308?

          1. 1

            But we are talking about floats, so that’s how you find the average between floats.

            For average between doubles, you obviously need to use triples, then quadruples, etc.

            1. 0

              Uh, triples and quadruples aren’t commonly-available data types. When people say “float” they almost always mean “double-precision float”, because that’s the most “native” type nowadays.

              Anyway, it would be extremely wasteful to try to convert doubles to some rare, higher-precision floating point type to handle this case.

              1. 1

                Oh c’mon, of course I know.

                The point was that the solution to the float problem was to use doubles but then it ends there…

                1. 0

                  A double is a float; single precision is very rarely used, and you’re not solving anything by doubling memory usage needlessly (if you can even doubling memory usage by finding a quad implementation for your programming language).

      2. 1

        And how about turning them into BigInt (without any decimal number and with a given precision P) doing all your fancy calculations and then dividing by P + converting the number back to float?

        A bit convoluted but then it doesn’t becomes too hard.

      Stories with similar links:

      1. Calculating the mean of a list of numbers authored by DRMacIver 5 years ago | 34 points | 16 comments