cjdoris / HugeNumbers.jl

Julia package for representing huge numbers
MIT License
5 stars 0 forks source link

Performance #2

Open gdalle opened 11 months ago

gdalle commented 11 months ago

The main drawback of LogarithmicNumbers for me is the (inevitable) performance hit of putting every single addition through a logsumexp. Is this package the same, slightly worse or slightly better?

cjdoris commented 11 months ago

I haven't done any benchmarking, but I expect they'll be comparable at arithmetic - the algorithms are very similar.

cjdoris commented 11 months ago

A large benefit of this package is in all the symmetric properties of the hexp function. It makes it much easier to write branchless code (which is easier to make type stable) - which is typically faster to run as a side effect.

You also don't waste another word of memory on the sign bit (you get to use the sign bit of the underlying value) which probably helps when you have lots of these.

Other symmetries mean that isinf, isnan, iszero, isone, signbit, abs, < etc all have trivial implementations, some of which will probably be a lot faster.

cjdoris commented 11 months ago

I'd be interested in a comparison.

gdalle commented 11 months ago

Do you think there is any aspect in which HugeNumbers can not replace / improve on LogarithmicNumbers?

cjdoris commented 11 months ago

Nothing springs to mind - the representations of both are based around logarithms, so implementing functions should be much the same either way.

cjdoris commented 11 months ago

TBH this package was born out of nerdy perfectionism more than utility - the hexp function is just so mathematically pleasing. I may never release it.

gdalle commented 11 months ago

I mean if it's simpler to code and works basically the same I see no reason not to make it available