Thread View: muc.lists.freebsd.bugs
17 messages
17 total messages
Started by bugzilla-noreply
Thu, 19 Nov 2026 00:03
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 00:03
Date: Thu, 19 Nov 2026 00:03
90 lines
5365 bytes
5365 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Bug ID: 300884
Summary: [libm] What to do about Bessel functions.
Product: Base System
Version: CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Many People
Priority: ---
Component: bin
Assignee: bugs@FreeBSD.org
Reporter: kargl@FreeBSD.org
Created attachment 277436
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277436&action=edit
whitespace cleanup
Cylindrical Bessel and Neumann functions were imported into FreeBSD in ancient
times
from NetBSD with lineage back to fdlibm. Little work (and apparently little
testing)
has been done with these functions. For simplicity, consider exhaustive
testing of
j0f(x) over the range of normal numbers:
% ./tlibm j0 -fPED -x min -X max
Interval tested for j0f: [1.17549e-38,3.40282e+38]
ulp <= 0.5: 68.721% 1464234486 | 68.721% 1464234486
0.5 < ulp <= 0.6: 3.541% 75438635 | 72.261% 1539673121
0.6 < ulp <= 0.7: 3.328% 70912912 | 75.589% 1610586033
0.7 < ulp <= 0.8: 3.117% 66412840 | 78.706% 1676998873
0.8 < ulp <= 0.9: 2.889% 61549741 | 81.595% 1738548614
0.9 < ulp <= 1.0: 2.646% 56376976 | 84.241% 1794925590
1.0 < ulp <= 1.5: 9.466% 201697211 | 93.707% 1996622801
1.5 < ulp <= 2.0: 4.263% 90827446 | 97.970% 2087450247
2.0 < ulp <= 3.0: 1.886% 40181343 | 99.856% 2127631590
3.0 < ulp : 0.144% 3074841 | 100.000% 2130706431
Max ulp: 3654467.50000000 at 3.15364697e+38 0x1.da821p+127
The group of values with ULP above 3.0 include value
near the zeros of j0f(x), e.g.,
% ./tlibm j0 -fa 2.40482545
x = 2.40482545e+00f, /* 0x1.33d152p+1, 0x4019e8a9 */
libm = 5.96342957e-08f, /* 0x1.00209ap-24, 0x3380104d */
mpfr = 5.64343985e-08f, /* 0x1.e4c48ep-25, 0x33726247 */
ULP = 900690.68928773
Yes, that is only one correct significant digit. Can we
do better. Yes. (Otherwise, there is no point in this
bug report). With a rewritten src/e_j0f.c, I have
% ./tlibm j0 -fPED -x min -X max
Interval tested for j0f: [1.17549e-38,3.40282e+38]
ulp <= 0.5: 99.990% 2130491097 | 99.990% 2130491097
0.5 < ulp <= 0.6: 0.010% 215331 | 100.000% 2130706428
0.6 < ulp <= 0.7: 0.000% 1 | 100.000% 2130706429
0.8 < ulp <= 0.9: 0.000% 1 | 100.000% 2130706430
3.0 < ulp : 0.000% 1 | 100.000% 2130706431
Max ulp: 4.61369371 at 3.15364697e+38 0x1.da821p+127
% ./tlibm j0 -fa 2.40482545
x = 2.40482545e+00f, /* 0x1.33d152p+1, 0x4019e8a9 */
libm = 5.64343985e-08f, /* 0x1.e4c48ep-25, 0x33726247 */
mpfr = 5.64343985e-08f, /* 0x1.e4c48ep-25, 0x33726247 */
ULP = 0.31071227
The 3 outliers with ULP > 0.6 occur for x > 0x1p127. If one is
using j0f(x) in this range of x, you're likely doing something
quite wrong.
The first patch in a hopefully series of patch is attached.
It is a whitespace cleanup of src/e_jn[f].c. It tries to
follow style(9) recommendations. Note, I only fixed leading
indentation of comments. Comments require much more effort to
cleanup and fix. Updating whitespace in e_j[01][f].c is
not done as I've rewritten those entirely.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 00:05
Date: Thu, 19 Nov 2026 00:05
15 lines
2452 bytes
2452 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #1 from Steve Kargl <kargl@FreeBSD.org> --- Forgot to mention the z_jn_patch1.diff was compiled tested and the md5 checksum for the unpatched and patched files match. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 06:44
Date: Thu, 19 Nov 2026 06:44
20 lines
2690 bytes
2690 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #2 from Steve Kargl <kargl@FreeBSD.org> --- Created attachment 277442 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277442&action=edit remove unnecessary cast, floating point suffix, and integer constants This patch removes unnecessary cast, use floating point suffix, and integer constants where possible. For example, '(float)1.0e9' becomes '1.e9f' and '2.0 / x' becomes '2 / x'. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 07:01
Date: Thu, 19 Nov 2026 07:01
18 lines
2513 bytes
2513 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #3 from Steve Kargl <kargl@FreeBSD.org> --- Created attachment 277444 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277444&action=edit Sort declaration Simple patch to sort the declarations in alphabetic order. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 22:11
Date: Thu, 19 Nov 2026 22:11
21 lines
2710 bytes
2710 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #4 from Steve Kargl <kargl@FreeBSD.org> --- Created attachment 277488 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277488&action=edit Review and update comments This patch reviewed the comments. Additional text is added to a few comments. One comment is moved to above the code to which it applies. There are a few comments that need to be expanded to explain the algorithm. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 22:12
Date: Thu, 19 Nov 2026 22:12
18 lines
2673 bytes
2673 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277442|remove unnecessary cast, |remove unnecessary cast,
description|floating point suffix, and |use floating point suffix,
|integer constants |and use integer constants
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 23:32
Date: Thu, 19 Nov 2026 23:32
20 lines
2688 bytes
2688 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bugmeister@FreeBSD.org
--- Comment #5 from Mark Linimon <linimon@FreeBSD.org> ---
^Triage: I'm confused. Are all these patches cumulative, or does the latest
one obsolete the previous 3?
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Fri, 20 Nov 2026 00:38
Date: Fri, 20 Nov 2026 00:38
47 lines
3225 bytes
3225 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #6 from Steve Kargl <kargl@FreeBSD.org> --- (In reply to Mark Linimon from comment #5) Well, that's a good question as I'm not a git user and just learned about 'git add' and 'git commit'. So, I did cd /usr/src git pull -ff cd lib/msun nedit src/e_jn*.c git diff src/e_jn*.c > z_jn_patch1.diff git add src/e_jn*.c git commit src/e_jn*.c nedit src/e_jn*.c git diff src/e_jn*.c > z_jn_patch2.diff git add src/e_jn*.c git commit src/e_jn*.c nedit src/e_jn*.c git diff src/e_jn*.c > z_jn_patch3.diff git add src/e_jn*.c git commit src/e_jn*.c nedit src/e_jn*.c git diff src/e_jn*.c > z_jn_patch4.diff git add src/e_jn*.c git commit src/e_jn*.c Looking at the diff files suggest that the files need to be committed in the order in which they were created. Have no idea how to get one comprehensive diff nor do I know how to remove the changes from my repository to return it to a pristine copy of master. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Fri, 20 Nov 2026 18:01
Date: Fri, 20 Nov 2026 18:01
27 lines
2695 bytes
2695 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
--- Comment #7 from Steve Kargl <kargl@FreeBSD.org> ---
Attached diff with incorrect editing of e_jnf.c. The sorting left
'di' declared twice:
@@ -30,9 +30,8 @@ static const float zero = 0.0000000000e+00;
float
jnf(int n, float x)
{
- int32_t i, hx, ix, sgn;
- float a, b, temp, di;
- float z, w;
+ int32_t hx, i, ix, sgn;
+ float a, b, di, temp, di, w, z;
once z_jn_patch3.diff is applied, one needs to remove the 2nd 'di'
in the declaration.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Fri, 20 Nov 2026 21:29
Date: Fri, 20 Nov 2026 21:29
22 lines
2723 bytes
2723 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #8 from Steve Kargl <kargl@FreeBSD.org> --- Created attachment 277506 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277506&action=edit Update handling of special cases x = +-0 and x = +-inf This patch updates the handling of special cases of x = +-0 and x = +-inf. These cases now immediately follow the x = NaN case, and prior to the manipulations for a negative order and taking x = fabs[f](x). So, a minor optimization. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Sat, 21 Nov 2026 00:19
Date: Sat, 21 Nov 2026 00:19
20 lines
2639 bytes
2639 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884 --- Comment #9 from Steve Kargl <kargl@FreeBSD.org> --- Created attachment 277509 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277509&action=edit Save calls to j0[f] and j1[f] The functions j0[f](x) and j1[f](x) are always called (except if x > 0x1p302 in jn(x) but that's a distraction here). This patch essentially caches the the values for use in the n >= 2 case. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Sat, 21 Nov 2026 19:26
Date: Sat, 21 Nov 2026 19:26
64 lines
4413 bytes
4413 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
--- Comment #10 from Steve Kargl <kargl@FreeBSD.org> ---
Created attachment 277540
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277540&action=edit
Update/fix handling of tiny, finite values of x
This is the first functional change to jn(x) and jnf(x). For tiny
x, the cylindrical Bessel function is approximated by the first
term in its Taylor series representation, jn(x) = (1/n!)*(x/2)^n,
where n! is a factorial and (x/2)^n is (x/2) raised to the nth power.
Prior to this patch, magic numbers are used with no explanation for
their choice. Here's the code
if (ix < 0x3e100000) { /* x < 2**-29 */
if (n > 33) /* underflow */
b = zero;
else {
temp = x * 0.5;
b = temp;
for (a = one, i = 2; i <= n; i++) {
a *= i; /* a = n! */
b *= temp; /* b = (x/2)^n */
}
b = b / a;
}
} else
First, 2**-29 is likely selected as a threshold because a two term
approximation is jn(x) = (1/n!)*(x/2)^n * [1 - (x/2)^2/(n+1)]. With
0x1p-29, the 2nd term in square brackets is 0x1p-60/(n+1) and we
have n >= 2 here. This term is less than DBL_EPSILON, so [...] = 1.
This choice is quite conservative, and could have been 0x1p-25.
Using the two term approximation allows for 0x1p-23 (if not a
bit larger).
Second, 33 seems to come -1024/(-29) ~ 35, that is (0x1p-29)^33
underflows when one considers the presence of the factorial. But,
the shortcut for n > 33 sets b to zero without raising FE_UNDERFLOW.
Third, the for-loops executes n-2 times, which may unnecessarily
compute zero multiply times. Consider x = 0x1p-600 and n = 20.
The first iteration underflows to zero; yet, another 17 iterations
are computed.
Fourth, accumulating the factorial in 'a' and the powers of (x/2)
in b is not needed.
Fifth, when the double precision jn(x) was converted the float jnf(x),
the magic numbers were left unchanged. Given that FLT_TRUE_MIN
is 0x1p-149, so with 0x1p-29 at most 5 iterations are needed before
underflow occurs. The magic number 33 is unneeded, and removed by
the patch.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 06:23
Date: Tue, 24 Nov 2026 06:23
25 lines
2822 bytes
2822 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277442|0 |1
is obsolete| |
--- Comment #11 from Steve Kargl <kargl@FreeBSD.org> ---
Comment on attachment 277442
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277442
remove unnecessary cast, use floating point suffix, and use integer constants
The 2nd patch in the series contained unintended changes.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 06:24
Date: Tue, 24 Nov 2026 06:24
25 lines
2742 bytes
2742 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277444|0 |1
is obsolete| |
--- Comment #12 from Steve Kargl <kargl@FreeBSD.org> ---
Comment on attachment 277444
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277444
Sort declaration
The 2nd patch in the series contained unintended changes.
Patch 3 depends on patch 2.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 06:25
Date: Tue, 24 Nov 2026 06:25
25 lines
2799 bytes
2799 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277488|0 |1
is obsolete| |
--- Comment #13 from Steve Kargl <kargl@FreeBSD.org> ---
Comment on attachment 277488
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277488
Review and update comments
The 2nd patch in the series contained unintended changes.
Other patches depend on patch 2.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 06:26
Date: Tue, 24 Nov 2026 06:26
25 lines
2797 bytes
2797 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277509|0 |1
is obsolete| |
--- Comment #15 from Steve Kargl <kargl@FreeBSD.org> ---
Comment on attachment 277509
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277509
Save calls to j0[f] and j1[f]
The 2nd patch in the series contained unintended changes.
Patch 3 depends on patch 2.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300884] [libm] What to do about Bessel functions.
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 06:26
Date: Tue, 24 Nov 2026 06:26
25 lines
2824 bytes
2824 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300884
Steve Kargl <kargl@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #277540|0 |1
is obsolete| |
--- Comment #16 from Steve Kargl <kargl@FreeBSD.org> ---
Comment on attachment 277540
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277540
Update/fix handling of tiny, finite values of x
The 2nd patch in the series contained unintended changes.
Other patches depends on patch 2.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads