multidouble 6.1.0

Double-double, quad-double and octo-double arithmetic, scalar and 8-lane SIMD (AVX-512, AVX2, SSE2, NEON, portable) with bitwise identical results, dual numbers and LU solves
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
//! The exponential and the natural logarithm of the double-double, quad-double and octo-double types (`exp`, `ln`,
//! with `f64`'s names and special values), written once over each precision's operations (`Prec`).
//!
//! * exp: x = k ln 2 + r with k = round(x_0 / ln 2) and |r| <= ln 2 / 2 + 2^-41, in the manner of W. J. Cody and
//!   W. Waite (Software Manual for the Elementary Functions, Prentice-Hall, 1980): ln 2 = `LN2_HI` + `LN2_LO`, with
//!   `LN2_HI` of 42 bits, so that k `LN2_HI` and x_0 - k `LN2_HI` are exact for |k| < 2^11, and r is that difference
//!   with x's lower parts, plus `LN2_LO` times -k, in one addition of the precision. Then r is scaled by 2^-m, m the
//!   least count that brings a bound of |r| below 2^-S; t ~ e^(r 2^-m) - 1 is the Taylor polynomial, by Horner's rule,
//!   as r' + r' (r' q), of degree `DEG` or, for a small r', of the least degree whose remainder is below 2^-B |r'|, so
//!   that no negligible term is formed; m steps t <- 2t + t^2 take t to e^r - 1, an error that grows by one rounding
//!   per step where squaring 1 + t would double it (the form of `exp` in the QD library of Y. Hida, X. S. Li and
//!   D. H. Bailey, version 2.3.7, src/dd_real.cpp and src/qd_real.cpp); and the result is (1 + t) 2^k, scaled exactly
//!   in two steps while its parts stay normal.
//! * ln: one Newton step on exp from y0, the double-double logarithm (for the double-double, `ln_f64` of the leading
//!   part, this module's own binary64 logarithm with a proven error, plus lo / hi; for a leading part at least 2^1023,
//!   that of x/2 plus ln 2, as x's double-double can round past f64::MAX there): with (k, t) the reduction of
//!   exp(-y0) above, x 2^k is exact and f = x 2^k - 1 is exact (its leading part lies in [1/2, 2], Sterbenz), so
//!   c = x e^(-y0) - 1 = (f + t) + f t keeps its relative accuracy near x = 1, and y = y0 + log(1 + c) with log(1 + c)
//!   = c (1 + c h(c)) to order `Q` (the QD library's own log takes y0 + c, the plain Newton step on exp, from f64's
//!   logarithm). `QD::ln` runs these steps with QD's operations, from the same start (`start_dd`) and with Q = 2, so
//!   its correction is c (1 - c/2).
//!
//! A product of a small factor is formed from the factor scaled by a power of two to below 2, from a bound of its
//! whole value (`bound_expo`), and scaled back after, so that no product's parts leave the normal range because the
//! argument is small; the scalings are exact while the parts stay normal, and each part that falls below 2^-1022 loses
//! at most 2^-1075.
//!
//! Error bounds (u = 2^-53): `OD::exp` errs by at most 3.661 u^8 e^x + 8 2^-1074 for a finite result, e^x below
//! f64::MAX + ulp/2 (an overflowing one is +inf, outside the bounds), and `OD::ln` by 9.926 u^8 |ln x| + 2^-509, for
//! inputs on the ladder |x_i| <= (2u)^i |x_0| whose run leaves no product, fused multiply-add or quotient below the
//! normal range (the paper's (A2), apart from the scalings above, whose losses the bounds include, and the products
//! that only choose k, m, the degree or a branch of ln), proved in the paper (paper/expansion-error-bounds.pdf,
//! Theorems 40 and 42) from Lemma 13 at every operation; `DD::exp` errs by at most 5.465 u^2 e^x + 2 2^-1074 for a
//! finite result, and `DD::ln` by 15.351 u^2 |ln x| + 2^-1071, for double-words under the same condition, from the
//! published bounds of the double-word operations they use and the proven bound of `ln_f64` (Proposition 44 and Lemma
//! 43). An emulator of these steps with every product hooked finds none below the normal range at any binade of the
//! argument, the closest 48 binades above it (`paper/explog_bits.py scan`), so the argument's size does not break the
//! condition there; a part far below the one above it can make a product underflow, as for the other operations. The
//! constants come from `paper/explog_consts.py`. The quad-double functions use QD's own operations, which have no
//! proven bounds, and are tested to: exp within 64 u^4 e^x + 4 2^-1074 for a finite result (the absolute term, as
//! above, from the parts that fall below 2^-1022), ln to 64 u^4 |ln x|.
//!
//! Range: exp gives +inf for x_0 > 709.79 and +0 for x_0 < -745.2, and computes in between, where an overflowing
//! result is +inf and an underflowing one loses its lower parts to the subnormals as the other operations do. ln
//! gives NaN for a negative or NaN leading part, -inf for a zero one and +inf for +inf, and works on every positive
//! finite value, subnormal leading parts included.
//!
//! Lanes: `DV`, `QV` and `OV` have `exp` and `ln` with each lane bitwise the scalar function of its value, on every
//! backend, so the bounds above hold per lane. The same code runs on them: each lane's choices (the special values, k,
//! m, the degree, the branches of ln) are made in f64 as the scalar types make them, the steps run as far as the lane
//! that needs most, and a lane keeps its value through each step it does not take (masked), so that it performs the
//! scalar type's operations and no others. A NaN's sign and payload follow the order of its operands, which the
//! compiler may change, so a lane whose result has a NaN part, possible only for a special value or for parts off the
//! ladder, takes the scalar function's result: the bits match, NaNs included.
use crate::dd::{two_sum, DD};
use crate::dv::{self, DV};
use crate::dw;
use crate::od::{Limb, OD};
use crate::ov::OV;
use crate::qd::QD;
use crate::qv::{self, QV};
use crate::simd::Simd;
use crate::v8::{M8, V8};

/// Deliberate breakage for the controls (feature `mutate`; ids below, 0 = none).
pub mod mutate {
    /// exp's reduction: ln 2's tail `LN2_LO` cut to its first part, an error of about |k| 2^-102 in r
    pub const RED_TAIL: u32 = 1;
    /// exp: the Taylor polynomial cut to half its degree
    pub const TAYLOR_HALF: u32 = 2;
    /// ln: the Newton step skipped, the start returned
    pub const LN_STEP: u32 = 3;
    /// ln: the double-double start (`ln_f64`) off by 2^-20 relative, past the error its proof allows
    pub const LN_START: u32 = 4;
    /// ln: log(1 + c) cut to c, an error of about c^2 / 2, below `OD::ln`'s absolute term near x = 1
    pub const LN_SERIES: u32 = 5;
    /// number of the ids that break the scalar functions (and with them the lanes)
    pub const N: u32 = 5;
    /// the lanes only: each lane skips the first step of its Horner sum (its mask off by one), the scalar types do not
    pub const LANE_STEP: u32 = 6;
    /// the lanes only: every lane scales its Horner sum by lane 0's powers of two
    pub const LANE_POW2_POLY: u32 = 7;
    /// the lanes only: every lane scales ln's f t by lane 0's powers of two
    pub const LANE_POW2_FT: u32 = 8;
    /// the lanes only: every lane scales ln's series by lane 0's powers of two
    pub const LANE_POW2_SERIES: u32 = 9;
    /// the lanes only: the lanes with a NaN part left as the lanes' arithmetic gives them, their NaNs' signs flipped,
    /// as another order of the operands can give them
    pub const LANE_NAN: u32 = 10;
    /// the mutations' descriptions, by id
    pub const NAMES: [&str; 11] = [
        "none",
        "exp: ln 2's tail cut to one part",
        "exp: Taylor polynomial at half its degree",
        "ln: Newton step skipped",
        "ln: start off by 2^-20",
        "ln: log(1 + c) cut to c",
        "lanes: first Horner step skipped",
        "lanes: lane 0's powers of two in the Horner sum",
        "lanes: lane 0's powers of two in ln's f t",
        "lanes: lane 0's powers of two in ln's series",
        "lanes: NaN lanes from the lanes' arithmetic, NaN signs flipped",
    ];

    #[cfg(feature = "mutate")]
    thread_local!(static ID: std::cell::Cell<u32> = const { std::cell::Cell::new(0) });

    /// select the mutation for the current thread (0 = none)
    #[cfg(feature = "mutate")]
    pub fn set(id: u32) {
        ID.with(|m| m.set(id));
    }

    /// whether mutation id is selected in the current thread
    #[cfg(feature = "mutate")]
    #[inline(always)]
    pub fn on(id: u32) -> bool {
        ID.with(|m| m.get() == id)
    }

    /// whether mutation id is selected: never, without the feature `mutate`
    #[cfg(not(feature = "mutate"))]
    #[inline(always)]
    pub fn on(_id: u32) -> bool {
        false
    }
}

/// exp is +inf above this leading part (e^709.79 > f64::MAX)
const EXP_MAX: f64 = 709.79;
/// exp is +0 at or below this leading part (e^-745.2 < 2^-1075)
const EXP_MIN: f64 = -745.2;

// generated by scripts/explog_constants.py, do not edit
/// ln 2 rounded to 42 significant bits: k LN2_HI is exact for every integer |k| < 2^11
const LN2_HI: f64 = f64::from_bits(0x3fe62e42fefa3800);
/// ln 2 - LN2_HI, greedy eight parts
const LN2_LO: [f64; 8] = [
    f64::from_bits(0x3d2ef35793c76730),
    f64::from_bits(0x398f97b57a079a19),
    f64::from_bits(0x3619ca62d8b62834),
    f64::from_bits(0x32b75b8baafa2be8),
    f64::from_bits(0xaf51e277e48514da),
    f64::from_bits(0x2bd56554bed2be87),
    f64::from_bits(0xa86de25a2a3947d9),
    f64::from_bits(0x24c0a213ab9d9489),
];
/// ln 2, greedy two parts
const LN2_DD: [f64; 2] = [f64::from_bits(0x3fe62e42fefa39ef), f64::from_bits(0x3c7abc9e3b39803f)];
/// 1/j! for j = 0..=43, greedy eight parts
const INV_FACT: [[f64; 8]; 44] = [
    [
        f64::from_bits(0x3ff0000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
    ],
    [
        f64::from_bits(0x3ff0000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
    ],
    [
        f64::from_bits(0x3fe0000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
        f64::from_bits(0x0000000000000000),
    ],
    [
        f64::from_bits(0x3fc5555555555555),
        f64::from_bits(0x3c65555555555555),
        f64::from_bits(0x3905555555555555),
        f64::from_bits(0x35a5555555555555),
        f64::from_bits(0x3245555555555555),
        f64::from_bits(0x2ee5555555555555),
        f64::from_bits(0x2b85555555555555),
        f64::from_bits(0x2825555555555555),
    ],
    [
        f64::from_bits(0x3fa5555555555555),
        f64::from_bits(0x3c45555555555555),
        f64::from_bits(0x38e5555555555555),
        f64::from_bits(0x3585555555555555),
        f64::from_bits(0x3225555555555555),
        f64::from_bits(0x2ec5555555555555),
        f64::from_bits(0x2b65555555555555),
        f64::from_bits(0x2805555555555555),
    ],
    [
        f64::from_bits(0x3f81111111111111),
        f64::from_bits(0x3c01111111111111),
        f64::from_bits(0x3881111111111111),
        f64::from_bits(0x3501111111111111),
        f64::from_bits(0x3181111111111111),
        f64::from_bits(0x2e01111111111111),
        f64::from_bits(0x2a81111111111111),
        f64::from_bits(0x2701111111111111),
    ],
    [
        f64::from_bits(0x3f56c16c16c16c17),
        f64::from_bits(0xbbef49f49f49f49f),
        f64::from_bits(0xb8827d27d27d27d2),
        f64::from_bits(0xb52f49f49f49f49f),
        f64::from_bits(0xb1c27d27d27d27d2),
        f64::from_bits(0xae6f49f49f49f49f),
        f64::from_bits(0xab027d27d27d27d2),
        f64::from_bits(0xa7af49f49f49f49f),
    ],
    [
        f64::from_bits(0x3f2a01a01a01a01a),
        f64::from_bits(0x3b6a01a01a01a01a),
        f64::from_bits(0x37aa01a01a01a01a),
        f64::from_bits(0x33ea01a01a01a01a),
        f64::from_bits(0x302a01a01a01a01a),
        f64::from_bits(0x2c6a01a01a01a01a),
        f64::from_bits(0x28aa01a01a01a01a),
        f64::from_bits(0x24ea01a01a01a01a),
    ],
    [
        f64::from_bits(0x3efa01a01a01a01a),
        f64::from_bits(0x3b3a01a01a01a01a),
        f64::from_bits(0x377a01a01a01a01a),
        f64::from_bits(0x33ba01a01a01a01a),
        f64::from_bits(0x2ffa01a01a01a01a),
        f64::from_bits(0x2c3a01a01a01a01a),
        f64::from_bits(0x287a01a01a01a01a),
        f64::from_bits(0x24ba01a01a01a01a),
    ],
    [
        f64::from_bits(0x3ec71de3a556c734),
        f64::from_bits(0xbb6c154f8ddc6c00),
        f64::from_bits(0x38071de3a556c734),
        f64::from_bits(0xb4ac154f8ddc6c00),
        f64::from_bits(0x31471de3a556c734),
        f64::from_bits(0xadec154f8ddc6c00),
        f64::from_bits(0x2a871de3a556c734),
        f64::from_bits(0xa72c154f8ddc6c00),
    ],
    [
        f64::from_bits(0x3e927e4fb7789f5c),
        f64::from_bits(0x3b3cbbc05b4fa99a),
        f64::from_bits(0xb7bc6d278883e8f5),
        f64::from_bits(0x34595567d3a50cce),
        f64::from_bits(0xb0c69c6f77527ad8),
        f64::from_bits(0xad310c717d2332e9),
        f64::from_bits(0xa9ccfa2aa85ae0b4),
        f64::from_bits(0x26611a5038eccd61),
    ],
    [
        f64::from_bits(0x3e5ae64567f544e4),
        f64::from_bits(0xbafc062e06d1f209),
        f64::from_bits(0x377c7880adcbc46e),
        f64::from_bits(0xb415553a6f0fed60),
        f64::from_bits(0xb09071c56e0d709d),
        f64::from_bits(0xad1d78e373529e26),
        f64::from_bits(0xa9b0e7aaaa3f1195),
        f64::from_bits(0xa625ab2e38d61b16),
    ],
    [
        f64::from_bits(0x3e21eed8eff8d898),
        f64::from_bits(0xbac2aec959e14c06),
        f64::from_bits(0x3742fb0073dd2d9e),
        f64::from_bits(0x33ec71d90b4ab715),
        f64::from_bits(0x308297b46da86d3b),
        f64::from_bits(0x2d12e097b663c827),
        f64::from_bits(0x29be975c71d013de),
        f64::from_bits(0x264f8c6f097b8a1a),
    ],
    [
        f64::from_bits(0x3de6124613a86d09),
        f64::from_bits(0x3a8f28e0cc748ebe),
        f64::from_bits(0xb727b2c4c8a840bc),
        f64::from_bits(0x33cc71cca1034c07),
        f64::from_bits(0xb06cbda1195605c6),
        f64::from_bits(0xad0aa25ed03f6b0e),
        f64::from_bits(0x29a8660e38e4ef5d),
        f64::from_bits(0x2641322fed0980c7),
    ],
    [
        f64::from_bits(0x3da93974a8c07c9d),
        f64::from_bits(0x3a305d6f8a2efd1f),
        f64::from_bits(0x36c3aa3346236a5d),
        f64::from_bits(0x336d75f096ea801e),
        f64::from_bits(0xafdb17039e931c58),
        f64::from_bits(0xac77321dbfeab8cd),
        f64::from_bits(0xa91f228a2870173f),
        f64::from_bits(0xa5b4424bda122cb9),
    ],
    [
        f64::from_bits(0x3d6ae7f3e733b81f),
        f64::from_bits(0x39e1d8656b0ee8cb),
        f64::from_bits(0xb626e142a138f825),
        f64::from_bits(0x32b43c0c38ccdcc6),
        f64::from_bits(0xaf5b225fe7ac8e6d),
        f64::from_bits(0x2bfa868cce37f24d),
        f64::from_bits(0x285f6ca1aa91de98),
        f64::from_bits(0x24ffaf1764148fe6),
    ],
    [
        f64::from_bits(0x3d2ae7f3e733b81f),
        f64::from_bits(0x39a1d8656b0ee8cb),
        f64::from_bits(0xb5e6e142a138f825),
        f64::from_bits(0x32743c0c38ccdcc6),
        f64::from_bits(0xaf1b225fe7ac8e6d),
        f64::from_bits(0x2bba868cce37f24d),
        f64::from_bits(0x281f6ca1aa91de98),
        f64::from_bits(0x24bfaf1764148fe6),
    ],
    [
        f64::from_bits(0x3ce952c77030ad4a),
        f64::from_bits(0x398ac981465ddc6c),
        f64::from_bits(0xb5a588b72e53bc5f),
        f64::from_bits(0x3227079e8909271a),
        f64::from_bits(0xaecc7cf0c326b1bd),
        f64::from_bits(0xab6599514ea5bf6f),
        f64::from_bits(0xa7815664674f395b),
        f64::from_bits(0x242fe4a25cc5a297),
    ],
    [
        f64::from_bits(0x3ca6827863b97d97),
        f64::from_bits(0x394eec01221a8b0b),
        f64::from_bits(0xb5e568798662118b),
        f64::from_bits(0x321f00d8b9e49291),
        f64::from_bits(0x2e8f90f119a4b758),
        f64::from_bits(0xab2332f2f09354d4),
        f64::from_bits(0xa7cc8130593f62de),
        f64::from_bits(0x24668e20905276c9),
    ],
    [
        f64::from_bits(0x3c62f49b46814157),
        f64::from_bits(0x38f2650f61dbdcb4),
        f64::from_bits(0xb5969502917cbf3b),
        f64::from_bits(0x320e35fbddac4553),
        f64::from_bits(0xaea729e1e158c7b1),
        f64::from_bits(0xab47d4e1832a5c10),
        f64::from_bits(0xa7e137983711ad17),
        f64::from_bits(0xa4703fa0d3c7ef66),
    ],
    [
        f64::from_bits(0x3c1e542ba4020225),
        f64::from_bits(0x387ea72b4afe3c2f),
        f64::from_bits(0xb5144020dfd65c8c),
        f64::from_bits(0xb186e69b50fc88ab),
        f64::from_bits(0xadf0c0c089e97a26),
        f64::from_bits(0xaa80b468eeb00d04),
        f64::from_bits(0x270ae5b62dd61c65),
        f64::from_bits(0xa398690c19647b2a),
    ],
    [
        f64::from_bits(0x3bd71b8ef6dcf572),
        f64::from_bits(0xb87d043ae40c4647),
        f64::from_bits(0x34f486121e81d5fe),
        f64::from_bits(0xb192d4ba8e1e64c7),
        f64::from_bits(0xae1eacf61a05d3bd),
        f64::from_bits(0xaaba0112e90a30d7),
        f64::from_bits(0x273ea2e421cbf0ee),
        f64::from_bits(0x23d41e29de668edf),
    ],
    [
        f64::from_bits(0x3b90ce396db7f853),
        f64::from_bits(0xb83aebcdbd20331c),
        f64::from_bits(0xb4d38a88578b4d75),
        f64::from_bits(0x316c0fbc29694fb8),
        f64::from_bits(0xae0a0fb9482f1340),
        f64::from_bits(0x2a9e2e59a7156b7c),
        f64::from_bits(0xa7247cd3fced75bc),
        f64::from_bits(0x23baee36286fbce3),
    ],
    [
        f64::from_bits(0x3b4761b41316381a),
        f64::from_bits(0xb7d3423c7d91404f),
        f64::from_bits(0x346e6135bfc1194a),
        f64::from_bits(0xb10ba7b1a3077b39),
        f64::from_bits(0x2d9b7bf8dd95d7a8),
        f64::from_bits(0x2a31330fbaaae84d),
        f64::from_bits(0x26ddee26f924ece4),
        f64::from_bits(0x237ddd5d53c82a5b),
    ],
    [
        f64::from_bits(0x3aff2cf01972f578),
        f64::from_bits(0xb789ada5fcc1ab14),
        f64::from_bits(0x342440ce7fd610dc),
        f64::from_bits(0xb0c26fcbc204fcd1),
        f64::from_bits(0x2d6e7ea849dc9d38),
        f64::from_bits(0x29e6eebfa38e8b12),
        f64::from_bits(0xa65613b59e762126),
        f64::from_bits(0x22f3e3e37dac6e75),
    ],
    [
        f64::from_bits(0x3ab3f3ccdd165fa9),
        f64::from_bits(0xb7458ddadf344487),
        f64::from_bits(0xb3ee8ed8001ad67e),
        f64::from_bits(0x30880a5edffcced7),
        f64::from_bits(0xad22e223a7c4ba1a),
        f64::from_bits(0x29cd44eb76543f36),
        f64::from_bits(0x2642b6be453e3aca),
        f64::from_bits(0xa2db899e29550d0c),
    ],
    [
        f64::from_bits(0x3a688e85fc6a4e5a),
        f64::from_bits(0xb7071c37ebd16540),
        f64::from_bits(0x33a494676265a364),
        f64::from_bits(0xb02397b40007db79),
        f64::from_bits(0xacc5dde19cf7f17a),
        f64::from_bits(0x2938fe6b9053a1b3),
        f64::from_bits(0xa5d519e12143cae4),
        f64::from_bits(0x227ead3f9a42560a),
    ],
    [
        f64::from_bits(0x3a1d1ab1c2dccea3),
        f64::from_bits(0x36a054d0c78aea14),
        f64::from_bits(0xb34196bf16c33a56),
        f64::from_bits(0x2fef0e65ed04d346),
        f64::from_bits(0x2c843a24f850a04f),
        f64::from_bits(0x292beceb85f33b63),
        f64::from_bits(0xa5cba31a2863d624),
        f64::from_bits(0x225781f675ab0344),
    ],
    [
        f64::from_bits(0x39d0a18a2635085d),
        f64::from_bits(0x366b9e2e28e1aa54),
        f64::from_bits(0x330a8549a9d99586),
        f64::from_bits(0xaf5141dcc8cc5668),
        f64::from_bits(0x2bd09cd93b9b8469),
        f64::from_bits(0x284d880d99ac4f03),
        f64::from_bits(0x24e4567f1bcd64fe),
        f64::from_bits(0xa1800ae73c8e8deb),
    ],
    [
        f64::from_bits(0x398259f98b4358ad),
        f64::from_bits(0x362eaf8c39dd9bc5),
        f64::from_bits(0xb2c6e29990a26fb6),
        f64::from_bits(0xaf42d867809b5568),
        f64::from_bits(0xabe15e662f862571),
        f64::from_bits(0x285afdee944e015d),
        f64::from_bits(0xa4f033796509b339),
        f64::from_bits(0xa19ac265171cf0cb),
    ],
    [
        f64::from_bits(0x3933932c5047d60e),
        f64::from_bits(0x35d832b7b530a627),
        f64::from_bits(0x3255d2c61f6d124c),
        f64::from_bits(0x2eff192b328d82c4),
        f64::from_bits(0xab575c254d35b232),
        f64::from_bits(0xa7f3379ca17bb8d4),
        f64::from_bits(0x2490a3414a95f91f),
        f64::from_bits(0x211ba74c079192d8),
    ],
    [
        f64::from_bits(0x38e434d2e783f5bc),
        f64::from_bits(0x3580b87b91be9aff),
        f64::from_bits(0x31fc89db1796db75),
        f64::from_bits(0xae98923b7699c8be),
        f64::from_bits(0x2af1d668aaebfb77),
        f64::from_bits(0x277f3d030c866cc8),
        f64::from_bits(0x2415c84cba83e83b),
        f64::from_bits(0xa0b34bc621ec3c31),
    ],
    [
        f64::from_bits(0x389434d2e783f5bc),
        f64::from_bits(0x3530b87b91be9aff),
        f64::from_bits(0x31ac89db1796db75),
        f64::from_bits(0xae48923b7699c8be),
        f64::from_bits(0x2aa1d668aaebfb77),
        f64::from_bits(0x272f3d030c866cc8),
        f64::from_bits(0x23c5c84cba83e83b),
        f64::from_bits(0xa0634bc621ec3c31),
    ],
    [
        f64::from_bits(0x3843981254dd0d52),
        f64::from_bits(0xb4e2b1f4c8015a2f),
        f64::from_bits(0xb18d82af23edb6db),
        f64::from_bits(0x2e2a1cd20123a99b),
        f64::from_bits(0x2ac958e5a4343645),
        f64::from_bits(0xa75c00bd1450f203),
        f64::from_bits(0xa3deb344a7d736aa),
        f64::from_bits(0x206c819525c289d0),
    ],
    [
        f64::from_bits(0x37f2710231c0fd7a),
        f64::from_bits(0x3473f8a2b4af9d6b),
        f64::from_bits(0x311c32215a9f317e),
        f64::from_bits(0xadad451e158a1205),
        f64::from_bits(0x2a4cf7b201892024),
        f64::from_bits(0xa6363ea01c78d66f),
        f64::from_bits(0xa2dc5f4a18322b80),
        f64::from_bits(0x1f57d50b7184b411),
    ],
    [
        f64::from_bits(0x37a0dc59c716d91f),
        f64::from_bits(0x343419e3fad3f031),
        f64::from_bits(0x30bd9d7ed1981ffc),
        f64::from_bits(0xad3345ea5d66a84b),
        f64::from_bits(0xa9c285e2b2f07400),
        f64::from_bits(0xa5e45683c242982b),
        f64::from_bits(0xa2881c9b83d61924),
        f64::from_bits(0x9f2f1fc2debd18ac),
    ],
    [
        f64::from_bits(0x374df983290c2ca9),
        f64::from_bits(0x33d5835c6895393b),
        f64::from_bits(0xb060578f45b1aaae),
        f64::from_bits(0xad0281508688972d),
        f64::from_bits(0xa99256a427c3a800),
        f64::from_bits(0xa59214035757a3b5),
        f64::from_bits(0x222c3eeb8766efbf),
        f64::from_bits(0x1eb1562eaf26c4ba),
    ],
    [
        f64::from_bits(0x36f9ec8d1c94e85b),
        f64::from_bits(0xb36670e9d4784ec6),
        f64::from_bits(0x30079fe5954939a2),
        f64::from_bits(0x2c882e418d9b0c9e),
        f64::from_bits(0x29126a441d4e7c8a),
        f64::from_bits(0x25b81814bbf34cbb),
        f64::from_bits(0x22546b74b00666dd),
        f64::from_bits(0x1ee7d7a47b670cc6),
    ],
    [
        f64::from_bits(0x36a5d4acb9c0c3ab),
        f64::from_bits(0xb326ec2c8f5b13b2),
        f64::from_bits(0x2fce2860aaa59188),
        f64::from_bits(0xac6866eba0408569),
        f64::from_bits(0x29088c546d54f915),
        f64::from_bits(0xa59f25e2debdf7ec),
        f64::from_bits(0xa2320fa2dfff537d),
        f64::from_bits(0x1eb27e3d933e1da3),
    ],
    [
        f64::from_bits(0x3651e99449a4bace),
        f64::from_bits(0xb2dfefbb89514b3c),
        f64::from_bits(0xaf753433f743a2d9),
        f64::from_bits(0x2bf25f70d1395dd7),
        f64::from_bits(0xa89a192c8c09ef53),
        f64::from_bits(0x252334e2e34edf6f),
        f64::from_bits(0xa1c588a6f96d60c8),
        f64::from_bits(0x1e305d79ede680e5),
    ],
    [
        f64::from_bits(0x35fca8ed42a12ae3),
        f64::from_bits(0x31fa07244abad2ab),
        f64::from_bits(0x2e9facdac6fb71b7),
        f64::from_bits(0xaacca2f486d514e1),
        f64::from_bits(0x273f1ff01aaea3dc),
        f64::from_bits(0x23dbe90be5f2217e),
        f64::from_bits(0xa056515e027fe5d1),
        f64::from_bits(0x1ce4be5200b75141),
    ],
    [
        f64::from_bits(0x35a65e61c39d0241),
        f64::from_bits(0xb23c0ed181727269),
        f64::from_bits(0xaebabbd2f56bbc2f),
        f64::from_bits(0xab518ff57fdc2e4e),
        f64::from_bits(0xa7f36ae11f3e65fa),
        f64::from_bits(0xa4925ae2605f425d),
        f64::from_bits(0x2126250e608382a2),
        f64::from_bits(0x1dc72185254caee6),
    ],
    [
        f64::from_bits(0x35510af527530de8),
        f64::from_bits(0x31eb626c912ee5c8),
        f64::from_bits(0x2e8349f032c6e859),
        f64::from_bits(0xab2ec616617f45c6),
        f64::from_bits(0x27bd2c9e0c7a83d1),
        f64::from_bits(0x245a880b4900483e),
        f64::from_bits(0x20e4a06700321962),
        f64::from_bits(0x1d8b18f5c51105ad),
    ],
    [
        f64::from_bits(0x34f95db45257e512),
        f64::from_bits(0x3186e5d72b6f79b9),
        f64::from_bits(0x2dcb830cf0b5b5c6),
        f64::from_bits(0x2a629276833f5728),
        f64::from_bits(0xa70b6b869bcfa969),
        f64::from_bits(0xa3a1da2df40a5f99),
        f64::from_bits(0xa021b5f4052c22d2),
        f64::from_bits(0x1cc237ba717f229d),
    ],
];
/// 1/3, greedy eight parts
const THIRD: [f64; 8] = [
    f64::from_bits(0x3fd5555555555555),
    f64::from_bits(0x3c75555555555555),
    f64::from_bits(0x3915555555555555),
    f64::from_bits(0x35b5555555555555),
    f64::from_bits(0x3255555555555555),
    f64::from_bits(0x2ef5555555555555),
    f64::from_bits(0x2b95555555555555),
    f64::from_bits(0x2835555555555555),
];
// end of generated constants

/// LN2_LO cut to its first part (`mutate::RED_TAIL`)
const LN2_LO_CUT: [f64; 8] = [LN2_LO[0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];

/// One precision's operations, in the forms the error bounds are proved for, on one value (`DD`, `QD`, `OD`) or on 8
/// lanes (`DV`, `QV`, `OV`). A per-lane array holds lane j at index j < L.
trait Prec: Copy {
    /// m squarings bring a bound of the reduced argument below 2^-S
    const S: i32;
    /// the Taylor polynomial's largest degree: |r'|^(DEG + 1) / (DEG + 1)! below 2^-12 of the unit roundoff for |r'| <
    /// 2^-S
    const DEG: usize;
    /// the order of ln's series of log(1 + c), for the start's error
    const Q: usize;
    /// 53 n + 12 for n parts: a term below 2^-B of the result's scale is negligible, 2^-12 of the unit roundoff
    const B: i32;
    /// the lanes: 1 for a scalar type, 8 for a lane type
    const L: usize = 1;
    /// every lane's bit
    const ALL: u8 = ((1u32 << Self::L) - 1) as u8;
    /// a condition per lane: bool, `M8` for the lanes
    type M: Copy;
    /// a count per lane, for the masks of the loops: i32, `V8` for the lanes
    type C: Copy;
    fn from_f64(x: f64) -> Self;
    /// lane j (v_j, 0, ...)
    #[inline(always)]
    fn from_f64s(v: &[f64; 8]) -> Self {
        Self::from_f64(v[0])
    }
    /// the leading parts
    fn his(self) -> [f64; 8];
    /// |x_0| + |x_1| + ... in f64, from the leading part down, per lane
    fn abs_sums(self) -> [f64; 8];
    /// the first parts of a greedy eight-part constant
    fn konst(c: &[f64; 8]) -> Self;
    /// lane j the first parts of c_j
    #[inline(always)]
    fn konsts(c: &[&[f64; 8]; 8]) -> Self {
        Self::konst(c[0])
    }
    fn plus(self, b: Self) -> Self;
    fn times(self, b: Self) -> Self;
    fn plus_one(self) -> Self;
    /// times a normal power of two, exact barring underflow and overflow
    fn times_pwr2(self, b: f64) -> Self;
    /// lane j times b_j, a normal power of two
    #[inline(always)]
    fn times_pwr2s(self, b: &[f64; 8]) -> Self {
        self.times_pwr2(b[0])
    }
    fn neg(self) -> Self;
    /// self - k ln 2 for an integer k (lane j k_j), 0 < |k| < 2^11, with ln 2 = LN2_HI + lo: (x_0 - k LN2_HI, x_1,
    /// ...), exact, plus lo times -k
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> Self;
    /// self - 1, exact for a leading part in [1/2, 2]
    fn sub_one(self) -> Self;
    /// ln's start
    fn ln_start(self) -> Self;
    /// ln's result from its start and the correction
    fn ln_finish(y0: Self, corr: Self) -> Self;
    /// the lanes of m's bits (bit j lane j)
    fn mask(m: u8) -> Self::M;
    fn counts(c: &[i32; 8]) -> Self::C;
    /// the lanes whose count exceeds i
    fn above(c: Self::C, i: i32) -> Self::M;
    /// per lane a where m holds, b elsewhere
    fn sel(m: Self::M, a: Self, b: Self) -> Self;
}

/// 2^k for -1022 <= k <= 1023
#[inline(always)]
fn pow2(k: i32) -> f64 {
    f64::from_bits(((k + 1023) as u64) << 52)
}

/// floor(log2 |h|) for a normal h, -1023 for a zero or subnormal one (the biased exponent field less 1023)
#[inline(always)]
fn expo(h: f64) -> i32 {
    ((h.to_bits() >> 52) & 0x7ff) as i32 - 1023
}

/// the exponent e of U = RN(RN(sum |v_i|) (1 + 2^-48)), 2^e <= U < 2^(e+1), -1023 for a zero or subnormal U: |v| <=
/// sum |v_i| <= U < 2^(e+1) whatever v's parts, where the leading part's exponent alone bounds nothing (a renormalized
/// expansion can be led by a part below half its value); per lane
#[inline(always)]
fn bound_expos<T: Prec>(v: T) -> [i32; 8] {
    let s = v.abs_sums();
    let mut e = [0; 8];
    for j in 0..T::L {
        e[j] = expo(s[j] * (1.0 + 2f64.powi(-48)));
    }
    e
}

/// a b for a with sum |a_i| < 2^(e+1) (`bound_expos`), -1022 <= e: formed as 2^e ((a 2^-e) b), so that the product's
/// parts are formed near b's scale and only the last power-of-two scaling, exact while the parts stay normal, can
/// leave the normal range; p = (2^-e, 2^e) per lane
#[inline(always)]
fn times_scaled<T: Prec>(a: T, p: &([f64; 8], [f64; 8]), b: T) -> T {
    a.times_pwr2s(&p.0).times(b).times_pwr2s(&p.1)
}

/// x 2^k in two exact steps, -1076 <= k <= 1076 (lane j k_j)
#[inline(always)]
fn scale<T: Prec>(x: T, k: &[i32; 8]) -> T {
    let (mut a, mut b) = ([1.0; 8], [1.0; 8]);
    for j in 0..T::L {
        let k1 = k[j] / 2;
        (a[j], b[j]) = (pow2(k1), pow2(k[j] - k1));
    }
    x.times_pwr2s(&a).times_pwr2s(&b)
}

/// the greatest of the lanes' counts, and at least 0
#[inline(always)]
fn most<T: Prec>(c: &[i32; 8]) -> i32 {
    let mut m = 0;
    for j in 0..T::L {
        m = m.max(c[j]);
    }
    m
}

/// a loop's step: new for the lanes whose count c exceeds i, old for the others; a scalar type's loop runs to its own
/// count, so it takes new without a select on its chain of steps
#[inline(always)]
fn step<T: Prec>(c: T::C, i: i32, new: T, old: T) -> T {
    if T::L == 1 {
        new
    } else {
        T::sel(T::above(c, i), new, old)
    }
}

/// the controls of the lanes' own powers of two (`mutate::LANE_POW2_POLY` and the others): every lane takes lane 0's
#[inline(always)]
fn lane0_pow2<T: Prec>(id: u32, p: &mut ([f64; 8], [f64; 8])) {
    if T::L > 1 && mutate::on(id) {
        *p = ([p.0[0]; 8], [p.1[0]; 8]);
    }
}

/// (k, t) with e^x ~ 2^k (1 + t), for |x_0| <= 745.2: the reduction, the Taylor polynomial and the squarings
#[inline(always)]
fn expm1_red<T: Prec>(x: T) -> ([i32; 8], T) {
    let h = x.his();
    let (mut k, mut red) = ([0.0; 8], 0u8);
    for j in 0..T::L {
        k[j] = (h[j] * std::f64::consts::LOG2_E).round();
        red |= ((k[j] != 0.0) as u8) << j;
    }
    // the lanes with k = 0 keep x
    let r = if red == 0 {
        x
    } else {
        let lo = if mutate::on(mutate::RED_TAIL) {
            &LN2_LO_CUT
        } else {
            &LN2_LO
        };
        T::sel(T::mask(red), x.reduce(&k, lo), x)
    };
    // m = max(0, e + S + 1) with 2^e <= RN(RN(sum |r_i|) (1 + 2^-48)) < 2^(e+1), so that |r| < 2^(e+1) and |r| 2^-m <
    // 2^-S whatever r's parts (a zero or subnormal sum gives e = -1023)
    let e = bound_expos(r);
    let (mut m, mut er, mut d) = ([0; 8], [0; 8], [1; 8]);
    let (mut sc, mut pm) = (0u8, [1.0; 8]);
    for j in 0..T::L {
        m[j] = (e[j] + T::S + 1).max(0);
        if m[j] > 0 {
            (sc, pm[j]) = (sc | 1 << j, pow2(-m[j]));
        }
        // the degree d = min(DEG, ceil(B / (-er - 1))), |r'| < 2^(er+1) <= 2^-S: the terms of degree above d sum to
        // below 2^-B |r'|, and none is formed, so a small r' forms no product of negligible size (d = 1 for |r'| <
        // 2^-B: t = r')
        er[j] = e[j] - m[j];
        let dj = if er[j] >= -1 - T::B {
            T::DEG.min((T::B / (-er[j] - 1) + (T::B % (-er[j] - 1) != 0) as i32) as usize) as i32
        } else {
            1
        };
        d[j] = if mutate::on(mutate::TAYLOR_HALF) {
            (dj / 2).max(1)
        } else {
            dj
        };
    }
    let r = if sc == 0 {
        r
    } else {
        T::sel(T::mask(sc), r.times_pwr2s(&pm), r)
    };
    let mut t = r;
    let dmax = most::<T>(&d);
    if dmax > 1 {
        // q = sum_(j=2)^d r^(j-2) / j! by Horner's rule, and t = r + r (r q), the outer product and sum in r 2^-er;
        // each lane starts at its own degree and keeps q through the steps above it
        let (mut c, mut poly) = ([&INV_FACT[1]; 8], 0u8);
        let mut pr = ([1.0; 8], [1.0; 8]);
        for j in 0..T::L {
            c[j] = &INV_FACT[d[j] as usize];
            if d[j] > 1 {
                (poly, pr.0[j], pr.1[j]) = (poly | 1 << j, pow2(-er[j]), pow2(er[j]));
            }
        }
        lane0_pow2::<T>(mutate::LANE_POW2_POLY, &mut pr);
        let skip = (T::L > 1 && mutate::on(mutate::LANE_STEP)) as i32;
        let dc = T::counts(&d);
        let mut q = T::konsts(&c);
        for i in (2..dmax).rev() {
            let s = T::konst(&INV_FACT[i as usize]).plus(r.times(q));
            q = step(dc, i + skip, s, q);
        }
        let w = r.times(q);
        let rs = r.times_pwr2s(&pr.0);
        t = T::sel(T::mask(poly), rs.plus(rs.times(w)).times_pwr2s(&pr.1), r);
    }
    // each lane squares m times
    let mc = T::counts(&m);
    for i in 0..most::<T>(&m) {
        t = step(mc, i, t.times_pwr2(2.0).plus(t.times(t)), t);
    }
    let mut ki = [0; 8];
    for j in 0..T::L {
        ki[j] = k[j] as i32;
    }
    (ki, t)
}

/// e^x (see the module doc)
#[inline(always)]
fn exp_of<T: Prec>(x: T) -> T {
    // the special values: x_0 itself for a NaN, +inf above EXP_MAX, +0 at or below EXP_MIN; their lanes run e^0
    let h = x.his();
    let (mut sp, mut v) = (0u8, [0.0; 8]);
    for j in 0..T::L {
        let s = if h[j].is_nan() {
            h[j]
        } else if h[j] > EXP_MAX {
            f64::INFINITY
        } else if h[j] <= EXP_MIN {
            // EXP_MIN = fl(-745.2) < -745.2, so this is x_0 < -745.2, the range the bounds' proofs leave out
            0.0
        } else {
            continue;
        };
        (sp, v[j]) = (sp | 1 << j, s);
    }
    if sp == T::ALL {
        return T::from_f64s(&v);
    }
    let x = if sp == 0 {
        x
    } else {
        T::sel(T::mask(sp), T::from_f64(0.0), x)
    };
    let (k, t) = expm1_red(x);
    let y = scale(t.plus_one(), &k);
    // an overflowing result is +inf
    let yh = y.his();
    let mut out = sp;
    for j in 0..T::L {
        if yh[j] == f64::INFINITY && sp >> j & 1 == 0 {
            (out, v[j]) = (out | 1 << j, f64::INFINITY);
        }
    }
    if out == 0 {
        y
    } else {
        T::sel(T::mask(out), T::from_f64s(&v), y)
    }
}

/// (-1)^(i+1) / i, the coefficients of log(1 + c), 2 <= i <= 4
#[inline(always)]
fn series<T: Prec>(i: usize) -> T {
    match i {
        2 => T::from_f64(-0.5),
        3 => T::konst(&THIRD),
        _ => T::from_f64(-0.25),
    }
}

/// ln x (see the module doc)
#[inline(always)]
fn ln_of<T: Prec>(x: T) -> T {
    // the special values: NaN for a negative or NaN x_0, -inf for a zero one, +inf for +inf; their lanes run ln 1
    let h = x.his();
    let (mut sp, mut v) = (0u8, [0.0; 8]);
    for j in 0..T::L {
        let s = if h[j].is_nan() || h[j] < 0.0 {
            f64::NAN
        } else if h[j] == 0.0 {
            f64::NEG_INFINITY
        } else if h[j] == f64::INFINITY {
            f64::INFINITY
        } else {
            continue;
        };
        (sp, v[j]) = (sp | 1 << j, s);
    }
    if sp == T::ALL {
        return T::from_f64s(&v);
    }
    let x = if sp == 0 {
        x
    } else {
        T::sel(T::mask(sp), T::from_f64(1.0), x)
    };
    let special = |y: T| {
        if sp == 0 {
            y
        } else {
            T::sel(T::mask(sp), T::from_f64s(&v), y)
        }
    };
    let y0 = x.ln_start();
    if mutate::on(mutate::LN_STEP) {
        return special(y0);
    }
    // e^-y0 ~ 2^k (1 + t); f = x 2^k - 1 exactly; c = x e^-y0 - 1 = (f + t) + f t, f t formed from f 2^-ef and t 2^-et,
    // both near 1, and dropped when |f| or |t| is below 2^-(B + 12), with ef and et the exponents of bounds of the
    // whole values (`bound_expos`), as the leading parts' do not bound them
    let (k, t) = expm1_red(y0.neg());
    let f = scale(x, &k).sub_one();
    let (ef, et) = (bound_expos(f), bound_expos(t));
    let (mut ft, mut pf, mut pt) = (0u8, ([1.0; 8], [1.0; 8]), ([1.0; 8], [1.0; 8]));
    for j in 0..T::L {
        if ef[j].min(et[j]) >= -T::B - 13 {
            ft |= 1 << j;
            (pf.0[j], pf.1[j]) = (pow2(-ef[j]), pow2(ef[j]));
            (pt.0[j], pt.1[j]) = (pow2(-et[j]), pow2(et[j]));
        }
    }
    lane0_pow2::<T>(mutate::LANE_POW2_FT, &mut pf);
    lane0_pow2::<T>(mutate::LANE_POW2_FT, &mut pt);
    let s = f.plus(t);
    let c = if ft == 0 {
        s
    } else {
        let p = f.times_pwr2s(&pf.0).times(t.times_pwr2s(&pt.0));
        T::sel(T::mask(ft), s.plus(p.times_pwr2s(&pf.1).times_pwr2s(&pt.1)), s)
    };
    // log(1 + c) = c (1 + c h), h = -1/2 + c (1/3 - c / 4 ...) to order Q, each product with c at the other factor's
    // scale; for |c| below 2^-(B + 12), c alone
    let ec = bound_expos(c);
    let (mut ser, mut pc) = (0u8, ([1.0; 8], [1.0; 8]));
    for j in 0..T::L {
        if !(ec[j] < -T::B - 13 || mutate::on(mutate::LN_SERIES)) {
            (ser, pc.0[j], pc.1[j]) = (ser | 1 << j, pow2(-ec[j]), pow2(ec[j]));
        }
    }
    lane0_pow2::<T>(mutate::LANE_POW2_SERIES, &mut pc);
    let corr = if ser == 0 {
        c
    } else {
        let mut h = series::<T>(T::Q);
        for i in (2..T::Q).rev() {
            h = series::<T>(i).plus(times_scaled(c, &pc, h));
        }
        T::sel(
            T::mask(ser),
            times_scaled(c, &pc, times_scaled(c, &pc, h).plus_one()),
            c,
        )
    };
    special(T::ln_finish(y0, corr))
}

/// the start of the quad-double and octo-double ln: the double-double ln of x's double-double, or, for a leading part
/// x_0 >= 2^1023, where that conversion can round past f64::MAX, the double-double ln of x/2's plus ln 2 (`LN2_DD`)
#[inline(always)]
fn start_dd(x0: f64, dd: impl Fn() -> DD, half: impl Fn() -> DD) -> DD {
    if x0 >= pow2(1023) {
        half().ln()
            + DD {
                hi: LN2_DD[0],
                lo: LN2_DD[1],
            }
    } else {
        dd().ln()
    }
}

/// `start_dd` on lanes: x/2's branch for the lanes with x_0 >= 2^1023, if any
#[inline(always)]
fn start_dv<S: Simd>(x0: V8<S>, dd: impl Fn() -> DV<S>, half: impl Fn() -> DV<S>) -> DV<S> {
    let big = x0.ge(V8::splat(pow2(1023)));
    if big.bits() == 0 {
        return dd().ln();
    }
    let y = <DV<S> as Prec>::sel(big, half(), dd()).ln();
    let l2 = DV::splat(DD {
        hi: LN2_DD[0],
        lo: LN2_DD[1],
    });
    <DV<S> as Prec>::sel(big, y + l2, y)
}

/// ln h for a positive finite h, within 5.915 u |ln h| (u = 2^-53; paper, Lemma 43), and 0 for h = 1: h = 2^e m
/// with m in (mu/2, mu], mu = RN(sqrt 2), m - 1 exact, and ln m = 2 atanh(s), s = (m - 1) / (m + 1), |s| <= 0.1716,
/// by the first ten terms of its series in s^2 (by Horner's rule with fused multiply-adds), whose remainder is below
/// 0.22 u relative; then e ln 2 is added by one fused multiply-add. No library logarithm is called, so the start of
/// `DD::ln` has a proven error. Public for the tests only.
#[doc(hidden)]
#[inline(always)]
pub fn ln_f64(h: f64) -> f64 {
    let (m, e) = ln_f64_split(h);
    ln_f64_sum(m, e as f64)
}

/// (m, e) of `ln_f64`'s h = 2^e m
#[inline(always)]
fn ln_f64_split(h: f64) -> (f64, i32) {
    let (h, e0) = if h < f64::MIN_POSITIVE {
        (h * pow2(54), -54)
    } else {
        (h, 0)
    };
    let mut e = expo(h) + e0;
    let mut m = f64::from_bits((h.to_bits() & 0x000f_ffff_ffff_ffff) | 0x3ff0_0000_0000_0000);
    if m > std::f64::consts::SQRT_2 {
        m *= 0.5;
        e += 1;
    }
    (m, e)
}

/// `ln_f64` from its m and e, written once for f64 and the lanes
#[inline(always)]
fn ln_f64_sum<L: Limb>(m: L, e: L) -> L {
    let one = L::splat(1.0);
    let s = m.sub(one).div(m.add(one));
    let z = s.mul(s);
    let mut v = L::splat(LN_SERIES[LN_SERIES.len() - 1]);
    for &c in LN_SERIES[..LN_SERIES.len() - 1].iter().rev() {
        v = z.fma(v, L::splat(c));
    }
    let y = e.fma(L::splat(std::f64::consts::LN_2), s.add(s).mul(v));
    if mutate::on(mutate::LN_START) {
        y.mul(L::splat(1.0 + 2f64.powi(-20)))
    } else {
        y
    }
}

/// `ln_f64` on lanes: m and e per lane in f64, the rest on the lanes
#[inline(always)]
fn ln_f64_lanes<S: Simd>(h: V8<S>) -> V8<S> {
    let h = h.to_array();
    let (mut m, mut e) = ([0.0; 8], [0.0; 8]);
    for j in 0..8 {
        let (mj, ej) = ln_f64_split(h[j]);
        (m[j], e[j]) = (mj, ej as f64);
    }
    ln_f64_sum(V8::<S>::from_array(m), V8::from_array(e))
}

/// 1 / (2j + 1) for j = 0..=9, rounded to nearest
const LN_SERIES: [f64; 10] = [
    1.0,
    1.0 / 3.0,
    1.0 / 5.0,
    1.0 / 7.0,
    1.0 / 9.0,
    1.0 / 11.0,
    1.0 / 13.0,
    1.0 / 15.0,
    1.0 / 17.0,
    1.0 / 19.0,
];

/// The per-lane items of a scalar type: one lane, its conditions bool and its counts i32.
macro_rules! one_lane {
    () => {
        type M = bool;
        type C = i32;
        #[inline(always)]
        fn mask(m: u8) -> bool {
            m & 1 != 0
        }
        #[inline(always)]
        fn counts(c: &[i32; 8]) -> i32 {
            c[0]
        }
        #[inline(always)]
        fn above(c: i32, i: i32) -> bool {
            c > i
        }
        #[inline(always)]
        fn sel(m: bool, a: Self, b: Self) -> Self {
            if m {
                a
            } else {
                b
            }
        }
    };
}

/// The double-double: `+` is AccurateDWPlusDW (Joldes, Muller, Popescu 2017, Theorem 3.1: 3u^2 / (1 - 4u)), `mul_f`
/// DWTimesFP3 (their Algorithm 9: 2u^2), and the products and the f64 sums are `dw::dw_times_dw2` and
/// `dw::dw_plus_fp`.
impl Prec for DD {
    const S: i32 = 1;
    const DEG: usize = 27;
    const Q: usize = 3;
    const B: i32 = 118;
    one_lane!();
    #[inline(always)]
    fn from_f64(x: f64) -> DD {
        DD::from_f64(x)
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        [self.hi; 8]
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        [self.hi.abs() + self.lo.abs(); 8]
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> DD {
        DD { hi: c[0], lo: c[1] }
    }
    #[inline(always)]
    fn plus(self, b: DD) -> DD {
        self + b
    }
    #[inline(always)]
    fn times(self, b: DD) -> DD {
        let (hi, lo) = dw::dw_times_dw2((self.hi, self.lo), (b.hi, b.lo));
        DD { hi, lo }
    }
    #[inline(always)]
    fn plus_one(self) -> DD {
        let (hi, lo) = dw::dw_plus_fp((self.hi, self.lo), 1.0);
        DD { hi, lo }
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> DD {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn neg(self) -> DD {
        -self
    }
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> DD {
        let k = k[0];
        let a = self.hi - k * LN2_HI;
        let p = DD { hi: lo[0], lo: lo[1] }.mul_f(-k);
        let (hi, lo) = dw::dw_plus_fp(dw::dw_plus_fp((p.hi, p.lo), self.lo), a);
        DD { hi, lo }
    }
    #[inline(always)]
    fn sub_one(self) -> DD {
        let (h, l) = two_sum(self.hi - 1.0, self.lo);
        DD { hi: h, lo: l }
    }
    /// the logarithm of the leading part (`ln_f64`), plus lo / hi
    #[inline(always)]
    fn ln_start(self) -> DD {
        DD::from_f64(ln_f64(self.hi) + self.lo / self.hi)
    }
    #[inline(always)]
    fn ln_finish(y0: DD, corr: DD) -> DD {
        let (hi, lo) = dw::dw_plus_fp((corr.hi, corr.lo), y0.hi);
        DD { hi, lo }
    }
}

/// The quad-double: QD's default `+` and `*` (the sloppy add and multiply), `add_f` and `mul_f`.
impl Prec for QD {
    const S: i32 = 6;
    const DEG: usize = 24;
    const Q: usize = 2;
    const B: i32 = 224;
    one_lane!();
    #[inline(always)]
    fn from_f64(x: f64) -> QD {
        QD::from_f64(x)
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        [self.x[0]; 8]
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        [self.x.iter().fold(0.0, |a, v| a + v.abs()); 8]
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> QD {
        QD {
            x: [c[0], c[1], c[2], c[3]],
        }
    }
    #[inline(always)]
    fn plus(self, b: QD) -> QD {
        self + b
    }
    #[inline(always)]
    fn times(self, b: QD) -> QD {
        self * b
    }
    #[inline(always)]
    fn plus_one(self) -> QD {
        self.add_f(1.0)
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> QD {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn neg(self) -> QD {
        -self
    }
    /// the exact x - k LN2_HI renormalized in any order (`QD::from_sum`), as QD's add expects ordered parts
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> QD {
        let (x, k) = (self.x, k[0]);
        QD::from_sum(x[0] - k * LN2_HI, x[1], x[2], x[3]) + QD::konst(lo).mul_f(-k)
    }
    #[inline(always)]
    fn sub_one(self) -> QD {
        let x = self.x;
        QD::from_sum(x[0] - 1.0, x[1], x[2], x[3])
    }
    #[inline(always)]
    fn ln_start(self) -> QD {
        QD::from_dd(start_dd(self.x[0], || self.to_dd(), || self.times_pwr2(0.5).to_dd()))
    }
    #[inline(always)]
    fn ln_finish(y0: QD, corr: QD) -> QD {
        y0 + corr
    }
}

/// The octo-double: the paper's ADD, MUL, ADDF and MULF (`+`, `*`, `add_f`, `mul_f`).
impl Prec for OD {
    const S: i32 = 6;
    const DEG: usize = 43;
    const Q: usize = 4;
    const B: i32 = 436;
    one_lane!();
    #[inline(always)]
    fn from_f64(x: f64) -> OD {
        OD::from_f64(x)
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        [self.x[0]; 8]
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        [self.x.iter().fold(0.0, |a, v| a + v.abs()); 8]
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> OD {
        OD { x: *c }
    }
    #[inline(always)]
    fn plus(self, b: OD) -> OD {
        self + b
    }
    #[inline(always)]
    fn times(self, b: OD) -> OD {
        self * b
    }
    #[inline(always)]
    fn plus_one(self) -> OD {
        self.add_f(1.0)
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> OD {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn neg(self) -> OD {
        -self
    }
    /// (x_0 - k LN2_HI, x_1, ..., x_7) as it is, an operand of `+` whatever its parts' order
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> OD {
        let (mut x, k) = (self, k[0]);
        x.x[0] = self.x[0] - k * LN2_HI;
        x + OD { x: *lo }.mul_f(-k)
    }
    /// exact: x_0 - 1 by Sterbenz, the other parts' two-sums with zero, and nine levels whose last is zero
    #[inline(always)]
    fn sub_one(self) -> OD {
        self.add_f(-1.0)
    }
    #[inline(always)]
    fn ln_start(self) -> OD {
        OD::from_dd(start_dd(self.x[0], || self.to_dd(), || self.times_pwr2(0.5).to_dd()))
    }
    /// y0 + corr, by `add_dd` (the bits of `+` with y0's zero parts)
    #[inline(always)]
    fn ln_finish(y0: OD, corr: OD) -> OD {
        corr.add_dd(DD {
            hi: y0.x[0],
            lo: y0.x[1],
        })
    }
}

/// the lanes of m's bits (bit j lane j)
#[inline(always)]
fn lane_mask<S: Simd>(m: u8) -> M8<S> {
    let mut a = [0.0; 8];
    for j in 0..8 {
        a[j] = (m >> j & 1) as f64;
    }
    V8::<S>::from_array(a).gt(V8::zero())
}

/// lane j (v_j, 0, ...) as parts
#[inline(always)]
fn from_f64s_parts<S: Simd, const N: usize>(v: &[f64; 8]) -> [V8<S>; N] {
    let mut r = [V8::zero(); N];
    r[0] = V8::from_array(*v);
    r
}

/// per lane 0 + |x_0| + |x_1| + ..., the scalar `abs_sums` of `QD` and `OD`
#[inline(always)]
fn abs_sums_parts<S: Simd, const N: usize>(x: &[V8<S>; N]) -> [f64; 8] {
    let mut s = V8::zero();
    for i in 0..N {
        s = s.add(x[i].abs());
    }
    s.to_array()
}

/// lane j the first N parts of c_j
#[inline(always)]
fn konsts_parts<S: Simd, const N: usize>(c: &[&[f64; 8]; 8]) -> [V8<S>; N] {
    let mut r = [V8::zero(); N];
    for i in 0..N {
        let mut a = [0.0; 8];
        for j in 0..8 {
            a[j] = c[j][i];
        }
        r[i] = V8::from_array(a);
    }
    r
}

/// lane j of every part times b_j, a normal power of two: `mul_pwr2` per lane
#[inline(always)]
fn pwr2_parts<S: Simd, const N: usize>(x: &[V8<S>; N], b: &[f64; 8]) -> [V8<S>; N] {
    debug_assert!(
        b.iter().all(|&v| crate::dd::is_pwr2(v)),
        "mul_pwr2: {b:?} are not all powers of two"
    );
    let b = V8::from_array(*b);
    let mut r = *x;
    for i in 0..N {
        r[i] = x[i].mul(b);
    }
    r
}

/// per lane a where m holds, b elsewhere, part by part
#[inline(always)]
fn sel_parts<S: Simd, const N: usize>(m: M8<S>, a: &[V8<S>; N], b: &[V8<S>; N]) -> [V8<S>; N] {
    let mut r = *b;
    for i in 0..N {
        r[i] = m.sel(a[i], b[i]);
    }
    r
}

/// The per-lane items of a lane type on backend S: 8 lanes, its conditions `M8` and its counts `V8`.
macro_rules! eight_lanes {
    ($s:ident) => {
        const L: usize = 8;
        type M = M8<$s>;
        type C = V8<$s>;
        #[inline(always)]
        fn mask(m: u8) -> M8<$s> {
            lane_mask(m)
        }
        #[inline(always)]
        fn counts(c: &[i32; 8]) -> V8<$s> {
            let mut a = [0.0; 8];
            for j in 0..8 {
                a[j] = c[j] as f64;
            }
            V8::from_array(a)
        }
        #[inline(always)]
        fn above(c: V8<$s>, i: i32) -> M8<$s> {
            c.gt(V8::splat(i as f64))
        }
    };
}

/// `DD`'s operations on 8 lanes, each lane bitwise `DD`'s.
impl<S: Simd> Prec for DV<S> {
    const S: i32 = <DD as Prec>::S;
    const DEG: usize = <DD as Prec>::DEG;
    const Q: usize = <DD as Prec>::Q;
    const B: i32 = <DD as Prec>::B;
    eight_lanes!(S);
    #[inline(always)]
    fn from_f64(x: f64) -> Self {
        DV::splat_f(x)
    }
    #[inline(always)]
    fn from_f64s(v: &[f64; 8]) -> Self {
        let [hi, lo] = from_f64s_parts(v);
        DV { hi, lo }
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        self.hi.to_array()
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        self.hi.abs().add(self.lo.abs()).to_array()
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> Self {
        DV::splat(DD { hi: c[0], lo: c[1] })
    }
    #[inline(always)]
    fn konsts(c: &[&[f64; 8]; 8]) -> Self {
        let [hi, lo] = konsts_parts(c);
        DV { hi, lo }
    }
    #[inline(always)]
    fn plus(self, b: Self) -> Self {
        self + b
    }
    #[inline(always)]
    fn times(self, b: Self) -> Self {
        let (hi, lo) = dw::dw_times_dw2((self.hi, self.lo), (b.hi, b.lo));
        DV { hi, lo }
    }
    #[inline(always)]
    fn plus_one(self) -> Self {
        let (hi, lo) = dw::dw_plus_fp((self.hi, self.lo), V8::splat(1.0));
        DV { hi, lo }
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> Self {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn times_pwr2s(self, b: &[f64; 8]) -> Self {
        let [hi, lo] = pwr2_parts(&[self.hi, self.lo], b);
        DV { hi, lo }
    }
    #[inline(always)]
    fn neg(self) -> Self {
        -self
    }
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> Self {
        let k = V8::from_array(*k);
        let a = self.hi.sub(k.mul(V8::splat(LN2_HI)));
        let p = DV::splat(DD { hi: lo[0], lo: lo[1] }).mul_v(k.neg());
        let (hi, lo) = dw::dw_plus_fp(dw::dw_plus_fp((p.hi, p.lo), self.lo), a);
        DV { hi, lo }
    }
    #[inline(always)]
    fn sub_one(self) -> Self {
        let (h, l) = dv::two_sum(self.hi.sub(V8::splat(1.0)), self.lo);
        DV { hi: h, lo: l }
    }
    #[inline(always)]
    fn ln_start(self) -> Self {
        DV {
            hi: ln_f64_lanes(self.hi).add(self.lo.div(self.hi)),
            lo: V8::zero(),
        }
    }
    #[inline(always)]
    fn ln_finish(y0: Self, corr: Self) -> Self {
        let (hi, lo) = dw::dw_plus_fp((corr.hi, corr.lo), y0.hi);
        DV { hi, lo }
    }
    #[inline(always)]
    fn sel(m: M8<S>, a: Self, b: Self) -> Self {
        let [hi, lo] = sel_parts(m, &[a.hi, a.lo], &[b.hi, b.lo]);
        DV { hi, lo }
    }
}

/// `QD`'s operations on 8 lanes, each lane bitwise `QD`'s.
impl<S: Simd> Prec for QV<S> {
    const S: i32 = <QD as Prec>::S;
    const DEG: usize = <QD as Prec>::DEG;
    const Q: usize = <QD as Prec>::Q;
    const B: i32 = <QD as Prec>::B;
    eight_lanes!(S);
    #[inline(always)]
    fn from_f64(x: f64) -> Self {
        QV::splat_f(x)
    }
    #[inline(always)]
    fn from_f64s(v: &[f64; 8]) -> Self {
        QV { c: from_f64s_parts(v) }
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        self.c[0].to_array()
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        abs_sums_parts(&self.c)
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> Self {
        QV::splat(<QD as Prec>::konst(c))
    }
    #[inline(always)]
    fn konsts(c: &[&[f64; 8]; 8]) -> Self {
        QV { c: konsts_parts(c) }
    }
    #[inline(always)]
    fn plus(self, b: Self) -> Self {
        self + b
    }
    #[inline(always)]
    fn times(self, b: Self) -> Self {
        self * b
    }
    #[inline(always)]
    fn plus_one(self) -> Self {
        self.add_f(1.0)
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> Self {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn times_pwr2s(self, b: &[f64; 8]) -> Self {
        QV {
            c: pwr2_parts(&self.c, b),
        }
    }
    #[inline(always)]
    fn neg(self) -> Self {
        -self
    }
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> Self {
        let (x, k) = (self.c, V8::from_array(*k));
        QV {
            c: qv::renorm4_any(x[0].sub(k.mul(V8::splat(LN2_HI))), x[1], x[2], x[3]),
        } + QV::splat(<QD as Prec>::konst(lo)).mul_v(k.neg())
    }
    #[inline(always)]
    fn sub_one(self) -> Self {
        let x = self.c;
        QV {
            c: qv::renorm4_any(x[0].sub(V8::splat(1.0)), x[1], x[2], x[3]),
        }
    }
    #[inline(always)]
    fn ln_start(self) -> Self {
        QV::from_dv(start_dv(self.c[0], || self.to_dv(), || self.mul_pwr2(0.5).to_dv()))
    }
    #[inline(always)]
    fn ln_finish(y0: Self, corr: Self) -> Self {
        y0 + corr
    }
    #[inline(always)]
    fn sel(m: M8<S>, a: Self, b: Self) -> Self {
        QV {
            c: sel_parts(m, &a.c, &b.c),
        }
    }
}

/// `OD`'s operations on 8 lanes, each lane bitwise `OD`'s.
impl<S: Simd> Prec for OV<S> {
    const S: i32 = <OD as Prec>::S;
    const DEG: usize = <OD as Prec>::DEG;
    const Q: usize = <OD as Prec>::Q;
    const B: i32 = <OD as Prec>::B;
    eight_lanes!(S);
    #[inline(always)]
    fn from_f64(x: f64) -> Self {
        OV::splat_f(x)
    }
    #[inline(always)]
    fn from_f64s(v: &[f64; 8]) -> Self {
        OV { c: from_f64s_parts(v) }
    }
    #[inline(always)]
    fn his(self) -> [f64; 8] {
        self.c[0].to_array()
    }
    #[inline(always)]
    fn abs_sums(self) -> [f64; 8] {
        abs_sums_parts(&self.c)
    }
    #[inline(always)]
    fn konst(c: &[f64; 8]) -> Self {
        OV::splat(OD { x: *c })
    }
    #[inline(always)]
    fn konsts(c: &[&[f64; 8]; 8]) -> Self {
        OV { c: konsts_parts(c) }
    }
    #[inline(always)]
    fn plus(self, b: Self) -> Self {
        self + b
    }
    #[inline(always)]
    fn times(self, b: Self) -> Self {
        self * b
    }
    #[inline(always)]
    fn plus_one(self) -> Self {
        self.add_f(1.0)
    }
    #[inline(always)]
    fn times_pwr2(self, b: f64) -> Self {
        self.mul_pwr2(b)
    }
    #[inline(always)]
    fn times_pwr2s(self, b: &[f64; 8]) -> Self {
        OV {
            c: pwr2_parts(&self.c, b),
        }
    }
    #[inline(always)]
    fn neg(self) -> Self {
        -self
    }
    #[inline(always)]
    fn reduce(self, k: &[f64; 8], lo: &[f64; 8]) -> Self {
        let (mut x, k) = (self, V8::from_array(*k));
        x.c[0] = self.c[0].sub(k.mul(V8::splat(LN2_HI)));
        x + OV::splat(OD { x: *lo }).mul_v(k.neg())
    }
    #[inline(always)]
    fn sub_one(self) -> Self {
        self.add_f(-1.0)
    }
    #[inline(always)]
    fn ln_start(self) -> Self {
        OV::from_dv(start_dv(self.c[0], || self.to_dv(), || self.mul_pwr2(0.5).to_dv()))
    }
    #[inline(always)]
    fn ln_finish(y0: Self, corr: Self) -> Self {
        corr.add_dv(DV {
            hi: y0.c[0],
            lo: y0.c[1],
        })
    }
    #[inline(always)]
    fn sel(m: M8<S>, a: Self, b: Self) -> Self {
        OV {
            c: sel_parts(m, &a.c, &b.c),
        }
    }
}

impl DD {
    /// e^self, within 5.465 u^2 e^x + 2 2^-1074 (u = 2^-53) for a double-word whose e^x is below f64::MAX + ulp/2, from
    /// the published bounds of the double-word operations it uses (see the module doc for the condition); +inf above
    /// 709.79 and where the result overflows, +0 below -745.2
    pub fn exp(self) -> DD {
        exp_of(self)
    }
    /// the natural logarithm, within 15.351 u^2 |ln x| + 2^-1071 for a double-word, from its own start `ln_f64` (see
    /// the module doc for the condition); NaN for a negative argument, -inf for zero
    pub fn ln(self) -> DD {
        ln_of(self)
    }
}

impl QD {
    /// e^self (see the module doc; QD's operations, tested to 64 u^4 e^x + 4 2^-1074 where e^x is below f64::MAX +
    /// ulp/2); +inf above 709.79 and where the result overflows, +0 below -745.2
    pub fn exp(self) -> QD {
        exp_of(self)
    }
    /// the natural logarithm (see the module doc; tested to 64 u^4 |ln x|); NaN for a negative argument, -inf for
    /// zero
    pub fn ln(self) -> QD {
        ln_of(self)
    }
}

impl OD {
    /// e^self, within 3.661 u^8 e^x + 8 2^-1074 (u = 2^-53) for an argument on the ladder whose e^x is below f64::MAX +
    /// ulp/2 (see the module doc for the condition); +inf above 709.79 and where the result overflows, +0 below -745.2
    pub fn exp(self) -> OD {
        exp_of(self)
    }
    /// the natural logarithm, within 9.926 u^8 |ln x| + 2^-509 for an argument on the ladder (see the module doc
    /// for the condition); NaN for a negative argument, -inf for zero
    pub fn ln(self) -> OD {
        ln_of(self)
    }
}

/// The lane types' scalar values, for the lanes whose result has a NaN part. Such a result needs a special value or
/// parts off the ladder. Its NaNs' signs and payloads follow the order of the operands, which the compiler may change,
/// so they can differ between the lanes' arithmetic and the scalar's, and between backends. Those lanes take the scalar
/// function's result, and every other lane is the lanes' own.
trait NanLanes: Copy {
    type Scalar: Copy;
    /// the lanes with a NaN part, bit j for lane j
    fn nan_lanes(self) -> u8;
    /// every NaN part's sign flipped (`mutate::LANE_NAN`)
    fn flip_nans(self) -> Self;
    /// self with each lane of m set to f of x's lane
    fn set_lanes(self, m: u8, x: Self, f: fn(Self::Scalar) -> Self::Scalar) -> Self;
}

/// the lanes with a NaN part, bit j for lane j
#[inline(always)]
fn nan_parts<S: Simd, const N: usize>(p: &[V8<S>; N]) -> u8 {
    let mut m = p[0].ne(p[0]);
    for i in 1..N {
        m = m.or(p[i].ne(p[i]));
    }
    m.bits()
}

/// every NaN part's sign flipped
fn flip_parts<S: Simd, const N: usize>(p: &[V8<S>; N]) -> [V8<S>; N] {
    let mut r = *p;
    for i in 0..N {
        r[i] = p[i].ne(p[i]).sel(p[i].neg(), p[i]);
    }
    r
}

impl<S: Simd> NanLanes for DV<S> {
    type Scalar = DD;
    #[inline(always)]
    fn nan_lanes(self) -> u8 {
        nan_parts(&[self.hi, self.lo])
    }
    fn flip_nans(self) -> Self {
        let [hi, lo] = flip_parts(&[self.hi, self.lo]);
        DV { hi, lo }
    }
    fn set_lanes(self, m: u8, x: Self, f: fn(DD) -> DD) -> Self {
        let (mut hi, mut lo) = (self.hi.to_array(), self.lo.to_array());
        for j in 0..8 {
            if m >> j & 1 == 1 {
                let y = f(x.lane(j));
                (hi[j], lo[j]) = (y.hi, y.lo);
            }
        }
        DV {
            hi: V8::from_array(hi),
            lo: V8::from_array(lo),
        }
    }
}

impl<S: Simd> NanLanes for QV<S> {
    type Scalar = QD;
    #[inline(always)]
    fn nan_lanes(self) -> u8 {
        nan_parts(&self.c)
    }
    fn flip_nans(self) -> Self {
        QV { c: flip_parts(&self.c) }
    }
    fn set_lanes(self, m: u8, x: Self, f: fn(QD) -> QD) -> Self {
        let (mut v, x) = (self.lanes(), x.lanes());
        for j in 0..8 {
            if m >> j & 1 == 1 {
                v[j] = f(x[j]);
            }
        }
        QV::from_lanes(&v)
    }
}

impl<S: Simd> NanLanes for OV<S> {
    type Scalar = OD;
    #[inline(always)]
    fn nan_lanes(self) -> u8 {
        nan_parts(&self.c)
    }
    fn flip_nans(self) -> Self {
        OV { c: flip_parts(&self.c) }
    }
    fn set_lanes(self, m: u8, x: Self, f: fn(OD) -> OD) -> Self {
        let (mut v, x) = (self.lanes(), x.lanes());
        for j in 0..8 {
            if m >> j & 1 == 1 {
                v[j] = f(x[j]);
            }
        }
        OV::from_lanes(&v)
    }
}

/// v, with the lanes that have a NaN part set to f of x's lane, f called through a pointer the compiler cannot see, so
/// that it is the scalar function's own code; one compare per part on the lanes without a NaN
#[inline(always)]
fn scalar_nans<T: NanLanes>(x: T, v: T, f: fn(T::Scalar) -> T::Scalar) -> T {
    let m = v.nan_lanes();
    if m == 0 {
        return v;
    }
    if mutate::on(mutate::LANE_NAN) {
        return v.flip_nans();
    }
    v.set_lanes(m, x, std::hint::black_box(f))
}

impl<S: Simd> DV<S> {
    /// e^x on every lane, each lane bitwise `DD::exp` of its value
    #[inline]
    pub fn exp(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, exp_of(self), DD::exp),
        )
    }
    /// ln x on every lane, each lane bitwise `DD::ln` of its value
    #[inline]
    pub fn ln(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, ln_of(self), DD::ln),
        )
    }
}

impl<S: Simd> QV<S> {
    /// e^x on every lane, each lane bitwise `QD::exp` of its value
    #[inline]
    pub fn exp(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, exp_of(self), QD::exp),
        )
    }
    /// ln x on every lane, each lane bitwise `QD::ln` of its value
    #[inline]
    pub fn ln(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, ln_of(self), QD::ln),
        )
    }
}

impl<S: Simd> OV<S> {
    /// e^x on every lane, each lane bitwise `OD::exp` of its value
    #[inline]
    pub fn exp(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, exp_of(self), OD::exp),
        )
    }
    /// ln x on every lane, each lane bitwise `OD::ln` of its value
    #[inline]
    pub fn ln(self) -> Self {
        S::vectorize(
            #[inline(always)]
            || scalar_nans(self, ln_of(self), OD::ln),
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::exact::{BigU, Dy};

    /// |sum parts - num / den| <= 2^lim2 |num / den|, in exact arithmetic: |den sum - num| 2^-lim2 <= num
    fn within(parts: &[f64], num: &Dy, den: &Dy, lim2: i64) -> bool {
        let d = Dy::sum(parts).mul(den).sub(num).abs();
        d.ldexp(-lim2).cmp_abs(num) != std::cmp::Ordering::Greater
    }

    /// ln 2 from sum 1/(j 2^j) in 1600-bit fixed point, within 2^-1585 below: no code shared with the generator
    fn ln2() -> Dy {
        let p = 1600u64;
        let mut s = BigU::zero();
        for j in 1..=p {
            s = s.add(&BigU::from_u64(1).shl(p - j).divrem_small(j).0);
        }
        Dy {
            neg: false,
            m: s,
            e: -(p as i64),
        }
    }

    /// The generated constants against exact arithmetic: 1/j! and 1/3 to their eight-part greedy rounding (within
    /// 2^-423 relative), ln 2 against its series in Rust (LN2_HI + LN2_LO within 2^-466, LN2_DD within 2^-107), LN2_HI
    /// of 42 bits. Control: each check fails with the last part moved by 2^-421 of the value (2^-460 for ln 2, 2^-104
    /// for LN2_DD).
    #[test]
    fn constants_are_exact_roundings() {
        let one = Dy::from_f64(1.0);
        let mut f = Dy::from_f64(1.0);
        for (j, c) in INV_FACT.iter().enumerate() {
            if j > 0 {
                f = f.mul(&Dy::from_f64(j as f64));
            }
            assert!(within(c, &one, &f, -423), "1/{j}!");
            let mut bad = *c;
            bad[7] += 2f64.powi(-421) * c[0];
            assert!(!within(&bad, &one, &f, -423), "control 1/{j}!");
        }
        assert!(within(&THIRD, &one, &Dy::from_f64(3.0), -423));
        let mut bad = THIRD;
        bad[7] += 2f64.powi(-421) * THIRD[0];
        assert!(!within(&bad, &one, &Dy::from_f64(3.0), -423), "control 1/3");
        let mut lo = vec![LN2_HI];
        lo.extend_from_slice(&LN2_LO);
        let l2 = ln2();
        assert!(within(&lo, &l2, &one, -466), "ln 2");
        lo[8] += 2f64.powi(-460);
        assert!(!within(&lo, &l2, &one, -466), "control ln 2");
        assert_eq!(LN2_HI.to_bits() & ((1 << 11) - 1), 0, "LN2_HI has more than 42 bits");
        // LN2_DD, ln 2's greedy two parts, within 2^-107 relative, and its control
        assert!(within(&LN2_DD, &l2, &one, -107), "LN2_DD");
        let mut bad = LN2_DD;
        bad[1] += 2f64.powi(-104);
        assert!(!within(&bad, &l2, &one, -107), "control LN2_DD");
        assert!((LN2_HI - std::f64::consts::LN_2).abs() < 2f64.powi(-42));
    }
}