Re: deco-Math project, step 00_a: exact bin and dec 'ranges' (in gnumeric). follow up.

John Denker via gnumeric-list <[email protected]> Thu, 8 Jul 2021 14:47:34 -0700
Newsgroups gmane.comp.gnome.apps.gnumeric
Message-ID <[email protected]>
On 7/8/21 10:52 AM, b. via gnumeric-list wrote:

> is there anyone reading here who can help me to make the following snippet fit 
> into gnumeric? i'm not a programmer, i've put it together and tinkered with it a 
> bit, in LO Calc it gives me the exponent of an IEEE 754 'double' value as an 
> integer, in gnumeric error messages from the compiler.
>      double fVal1 = 0.0;
>      ...
>      fVal1 = GetDouble();
>      ...
>      auto pValParts1 = reinterpret_cast < const sal_math_Double * > (&fVal1);
>      int nbinExp1 = pValParts1->inf_parts.exponent - 1023;
> the alternatives 'log2(x)' or 'int(log2(x))' produce some - few - errors, just 
> below range borders, increasing with the magnitude of x as the log2 curve flattens.


I assume you are trying to emulate the C function frexp().

Here is a spreadsheet that does that. It's pretty straightforward:
  https://www.av8n.com/hack/frexp.gnumeric

That includes about 15 test cases.
The acid test is verifying that:
  a) The mantissa is in range, and
  b) The original input can be reconstructed exactly,
	using the computed exponent and mantissa.

I "think" the calculation can be simplified by using C4 instead of E4,
and getting rid of column E ... but I don't have a proof of this.