Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Nov 2024 21:12:33 +0000
From:      bugzilla-noreply@freebsd.org
To:        standards@FreeBSD.org
Subject:   [Bug 275661] /usr/bin/dc really slow with a trivial calculation
Message-ID:  <bug-275661-99-KumbUPUxSR@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-275661-99@https.bugs.freebsd.org/bugzilla/>
References:  <bug-275661-99@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D275661

--- Comment #5 from Stefan E=C3=9Fer <se@FreeBSD.org> ---
(In reply to Stefan E=C3=9Fer from comment #4)
I have had some time to think about this issue, and improvements should be
possible for some cases without loss of precision of the results.

Error propagation allows to calculate the required number of digits in the
fractional part of intermediate results.

The following cases have to be distinguished:
 * base > 1 and positive exponent
 * base < 1 and positive exponent
 * base > 1 and negative exponent
 * base < 1 and negative exponent

A base value < 1 with negative exponent requires very high precision of
intermediate results:

Consider a base value of 0.1 and a negative exponent "n", which should retu=
rn
10^n for any scale >=3D 1 (i.e. at least 1 fractional digit). This requires
intermediate results to be calculated with n fractional digits (e.g.: 0.1^-=
4 =3D
1/(0.1 ^4) =3D 1/0.0001 =3D 10^4).

A possible optimization is to normalize the base value to have a leading di=
git
of 1..9 (i.e. multiply by a suitable power of 10; divide the result by that
multiplicator^n to get the result using only the required precision of the
result; multiplication by powers of 10 is a very efficient operation in this
bc/dc implementation).

The current implementation uses intermediate scale values (precision of the
fractional part) that are proportional to the exponent, but this is not
actually required for an exact result, if the above mentioned normalization=
 of
the base value is applied. For the test cases with scale=3D16 and
1.0000001^(2^27) the intermediate results will have 16*2^27 fractional digi=
ts
...

I'll calculate the error propagation for the cases of positive and for nega=
tive
exponents (assuming a base value >=3D 1 after applying the above mentioned
normalization).

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-275661-99-KumbUPUxSR>