Page MenuHomeFreeBSD

Update scalbn* functions to the musl versions
ClosedPublic

Authored by arichardson on Feb 22 2021, 6:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 7 2024, 3:05 PM
Unknown Object (File)
Feb 17 2024, 3:14 AM
Unknown Object (File)
Jan 17 2024, 3:39 AM
Unknown Object (File)
Dec 20 2023, 6:15 AM
Unknown Object (File)
Dec 14 2023, 10:46 PM
Unknown Object (File)
Dec 7 2023, 9:14 AM
Unknown Object (File)
Nov 7 2023, 10:03 AM
Unknown Object (File)
Nov 1 2023, 11:31 AM
Subscribers

Details

Summary

Minor change to scalbnl() to change musl's union ldshape back to
union IEEEl2bits.

Musl commit messages:
commit 8c44a060243f04283ca68dad199aab90336141db
Author: Szabolcs Nagy <nsz@port70.net>
Date: Mon Apr 3 02:38:13 2017 +0200

fix scalbn when result is in the subnormal range

in nearest rounding mode scalbn could introduce double rounding error
when an intermediate value and the final result were both in the
subnormal range e.g.

  scalbn(0x1.7ffffffffffffp-1, -1073)

returned 0x1p-1073 instead of 0x1p-1074, because the intermediate
computation got rounded to 0x1.8p-1023.

with the fix an intermediate value can only be in the subnormal range
if the final result is 0 which is correct even after double rounding.
(there still can be two roundings so signals may be raised twice, but
that's only observable with trapping exceptions which is not supported.)

commit 2eaed464e2080d8321d3903b71086a1ecfc4ee4a
Author: Szabolcs Nagy <nsz@port70.net>
Date: Wed Sep 4 15:52:54 2013 +0000

math: use float_t and double_t in scalbnf and scalbn

remove STRICT_ASSIGN (c99 semantics is assumed) and use the conventional
union to prepare the scaling factor (so libm.h is no longer needed)

commit 1b77b9072f374bd26eb0574b83a0d5f18d75ec60
Author: Szabolcs Nagy <nsz@port70.net>
Date: Thu Aug 15 10:07:46 2013 +0000

math: minor scalbn*.c simplification

commit c4359e01303da2755fe7e8033826b132eb3659b1
Author: Szabolcs Nagy <nsz@port70.net>
Date: Tue Nov 13 10:55:35 2012 +0100

math: excess precision fix modf, modff, scalbn, scalbnf

old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
now we use STRICT_ASSIGN to work around the issue.
(see note 160 in c11 section 6.8.6.4)

commit 666271c105e4137bdfa195e217799d74143370d4
Author: Szabolcs Nagy <nsz@port70.net>
Date: Tue Nov 13 10:30:40 2012 +0100

math: fix scalbn and scalbnf on overflow/underflow

old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
(see note 160 in n1570.pdf section 6.8.6.4)

commit 8051e08e10d2b739fcfcbc6bc7466e8d77fa49f1
Author: nsz <nsz@port70.net>
Date: Mon Mar 19 10:54:07 2012 +0100

simplify scalbn*.c implementations

The old scalbn.c was wrong and slow, the new one is just slow.
(scalbn(0x1p+1023,-2097) should give 0x1p-1074, but the old code gave 0)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

It's rather huge, and I'm unsure if the new implementation is much clearer than the old one, with all the magic numbers.... But it passes all current tests, and looks about one or two levels less scary. :)

That said, are there any particular additional tests for edge cases named in the original musl commits? (I.e. the "scalbn(0x1p+1023,-2097) should give 0x1p-1074, but the old code gave 0" remark.)

This revision is now accepted and ready to land.Feb 23 2021, 8:25 PM

These tests appear to be here: https://repo.or.cz/libc-test.git/tree/HEAD:/src/math

Maybe we can integrate some of those tests at some point in the future.