Improve Math.FrExp and LdExp.

Patch: frld.patch.

I have two complaints about FrExp: it FREEZES ON INFINITIES and can be VERY SLOW otherwise. I propose single / double / extended versions that work with binary representations.

LdExp is okay, but I re-done it as well:

  • My version gives correct answers in extreme cases where the answer is finite but IntPower overflows, like LdExp(extended(1e-3000), 17000) ≈ 3.23e+2117: extended has a maximum binary exponent of 16383, sabotaging the attempt to directly calculate 2¹⁷⁰⁰⁰. I even implemented correct rounding (“to nearest, ties to even”), so the result should always exactly match the finite result of actual multiplication (I hope). (This concern applies only to denormalized results of applying negative powers that lose precision.)

  • Whether it’s faster than before will depend on the platform. On my computer, it is slightly slower with SSE, but much faster with FPU; probably can be made consistently faster by not using FrExp internally, but that would be a further complication.

Demo: frld.pas.

Edited by Rika
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information