News for hackers. Stuff that matters.
Re:Faster Than Dijkstra? by pvillano on Friday February 13, 2026 @02:33PM (#47006742)
To be pedantic, median is cheaper than sorting. O(n) with a quicksort-like algorithm.

Also, if you're taking an average of floating point numbers, you might want to sort it first and add from smallest to largest, to better preserve precision

Re:Faster Than Dijkstra? by lscharen on Friday February 13, 2026 @03:09PM (#47007170)
An aside, but I recently learned -- if one is willing to use a very modest amount of memory -- summing floating-point numbers with no loss of precision is effectively a solved problem with the XSUM algorithm.

https://glizen.com/radfordneal/ftp/xsum.pdf

Re:Faster Than Dijkstra? by tialaramex on Friday February 13, 2026 @04:28PM (#47008090)
That paper explains some useful optimisation details, but obviously since the floats are all (either infinity or) some multiple of a known tiny fraction (their smallest non-zero number), we can definitely sum them accurately.
Re:Faster Than Dijkstra? by mjcohen on Friday February 13, 2026 @06:32PM (#47009313)
Not if the ratio between the largest and smallest floats is very large (2^(2^n)) where n is the number of bits in the exponent.
Re:Faster Than Dijkstra? by tialaramex on Friday February 13, 2026 @07:37PM (#47009953)
I think you either haven't thought about this or you did your math wrong.

You need (2^e)+m+1 bits. That is more bits than would fit in the cheap machine integer type you just have lying around, but it's not that many in real terms.

Let's do a tiny one to see though first, the "half-precision" or f16 type, 5 bits of exponent, 10 bits of fraction, 1 sign bit. We need 43 bits. This will actually fit in the 64-bit signed integer type on a modern CPU.

Now lets try f64, the big daddy, 11 exponent, 52 fraction, 1 sign bit so total 2048 + 52 + 1 = 2101 bits. As I said it doesn't fit in our machine integer types but it's much smaller than a kilobyte of RAM.

Edited: I can't count, though it doesn't make a huge difference.

Re:Faster Than Dijkstra? by LegionMammal978 on Saturday February 14, 2026 @05:04AM (#47013261)
You also need some extra bits at the top so that it doesn't overflow (e.g., on an adversarial input filled with copies of the max finite value, followed by just as many copies of its negation, so that it sums to 0). The exact number will depend on the maximum input length, but for arrays stored in addressible memory it will add up to no more than 64 or so.
Re:Faster Than Dijkstra? by tialaramex on Saturday February 14, 2026 @07:18AM (#47014004)
Thanks, you're right there for accumulating excess, I don't think you can actually get to 64 extra bits but sure, lets say 64 extra bits if you want a general purpose in memory algorithm, it's not cheap but we shouldn't be surprised it can be done.
Re:Faster Than Dijkstra? by hinkley on Sunday February 15, 2026 @12:01PM (#47025279)
That’s great for mean, but you don’t need to sort for mean.