[go: up one dir, main page]

lexical-core 0.6.5

Lexical, to- and from-string conversion routines.
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
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
//! Number format enumerations and bit masks.

// Sample test code for each language used:
//
//  Rust
//  ----
//
//  Setup:
//      Save to `main.rs` and run `rustc main.rs -o main`.
//
//  Code:
//      ```text
//      pub fn main() {
//          println!("{:?}", 3_.0f32);
//          println!("{:?}", "3_.0".parse::<f32>());
//      }
//      ```
//
// Python
// ------
//
//  Setup:
//      Run `python` to enter the interpreter.
//
//  Code:
//      ```text
//      print(3_.0)
//      print(float("3_.0"))
//      ```
//
//  C++
//  ---
//
//  Setup:
//      Save to `main.cc` and run `g++ main.cc -o main -std=c++XX`,
//      where XX is one of the following values:
//          - 98
//          - 03
//          - 11
//          - 14
//          - 17
//
//  Code:
//      ```text
//      #include <cstdlib>
//      #include <cstring>
//      #include <iostream>
//      #include <iterator>
//      #include <stdexcept>
//
//      double parse(const char* string) {
//          char* end;
//          double result = strtod(string, &end);
//          if (std::distance(string, reinterpret_cast<const char*>(end)) != strlen(string)) {
//              throw std::invalid_argument("did not consume entire string.");
//          }
//          return result;
//      }
//
//      int main() {
//          std::cout << 3'.0 << std::endl;
//          std::cout << parse("3'.0") << std::endl;
//      }
//      ```
//
//  C
//  -
//
//  Setup:
//      Save to `main.c` and run `gcc main.c -o main -std=cXX`,
//      where XX is one of the following values:
//          - 89
//          - 90
//          - 99
//          - 11
//          - 18
//
//  Code:
//      ```text
//      #include <stdint.h>
//      #include <stdlib.h>
//      #include <string.h>
//      #include <stdio.h>
//
//      size_t distance(const char* first, const char* last) {
//          uintptr_t x = (uintptr_t) first;
//          uintptr_t y = (uintptr_t) last;
//          return (size_t) (y - x);
//      }
//
//      double parse(const char* string) {
//          char* end;
//          double result = strtod(string, &end);
//          if (distance(string, (const char*) end) != strlen(string)) {
//              abort();
//          }
//          return result;
//      }
//
//      int main() {
//          printf("%f\n", 3'.);
//          printf("%f\n", parse("3'."));
//      }
//      ```
//
// Ruby
// ----
//
//  Setup:
//      Run `irb` to enter the interpreter.
//
//  Code:
//      ```text
//      puts 3.0_1;
//      puts "3.0_1".to_f;
//      ```
// Swift
// -----
//
//  Setup:
//      Run `swift` to enter the interpreter.
//
//  Code:
//      ```text
//      print(3.0);
//      print(Float("3.0"));
//      ```
// Golang
// ------
//
// Setup:
//      Save to `main.go` and run `go run main.go`
//
// Code:
//      ```text
//      package main
//
//      import (
//          "fmt"
//          "strconv"
//      )
//
//      func main() {
//          fmt.Println(3.0)
//          fmt.Println(strconv.ParseFloat("3.0", 64))
//      }
//      ```
//
// Haskell
// -------
//
// Setup:
//      Run `ghci` to enter the interpreter.
//
// Code:
//      ```text
//      :m Numeric
//      showFloat 3.0 ""
//      let x = "3.0"
//      read x :: Float
//      ```
//
// Javascript
// ----------
//
// Setup:
//      Run `nodejs` (or `node`) to enter the interpreter.
//
// Code:
//      ```text
//          console.log(3.0)
//          console.log(parseFloat("3.0"))
//      ```
//
// Perl
// ----
//
// Setup:
//      Run `perl -de1` to enter the interpret.
//
// Code:
//      ```text
//      print 3.01;
//      print '3.01' * 1;
//      ```
//
// PHP
// ---
//
// Setup:
//      Run `php -a` to enter the interpret.
//
// Code:
//      ```text
//      printf("%f\n", 3.0);
//      printf("%f\n", floatval("3.0"));
//      ```
//
// Java
// ----
//
// Setup:
//      Save to `main.java` and run `javac main.java`, then run `java Main`.
//
// Code:
//      ```text
//      class Main {
//          public static void main(String args[]) {
//              System.out.println(3.0);
//              System.out.println(Float.parseFloat("3.0"));
//          }
//      }
//      ```
//
// R
// -
//
// Setup:
//      Run `R` to enter the interpret.
//
// Code:
//      ```text
//      print(3.0);
//      print(as.numeric("3.0"));
//      ```
//
// Kotlin
// ------
//
// Setup:
//      Save file to `main.kt` and run `kotlinc main.kt -d main.jar`,
//      then run `java -jar main.jar`.
//
// Code:
//      ```text
//      fun main() {
//          println(3.0)
//          println("3.0".toDouble())
//      }
//      ```
//
// Julia
// -----
//
// Setup:
//      Run `julia` to enter the interpret.
//
// Code:
//      ```text
//      print(3.0);
//      print(parse(Float64, "3.0"));
//      ```
//
// C#
// --
//
// Note:
//      Mono accepts both integer and fraction decimal separators, Mono is
//      just buggy, see https://github.com/dotnet/csharplang/issues/55#issuecomment-574902516.
//
// Setup:
//      Run `csharp -langversion:X` to enter the interpret,
//      where XX is one of the following values:
//          - ISO-1
//          - ISO-2
//          - 3
//          - 4
//          - 5
//          - 6
//          - 7
//
// Code:
//      ```text
//      Console.WriteLine("{0}", 3.0);
//      Console.WriteLine("{0}", float.Parse("3.0"));
//      ```
//
// Kawa
// ----
//
// Setup:
//      Run `kawa` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      (string->number "3.0")
//      ```
//
// Gambit-C
// --------
//
// Setup:
//      Run `gsc` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      (string->number "3.0")
//      ```
//
// Guile
// -----
//
// Setup:
//      Run `guile` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      (string->number "3.0")
//      ```
//
// Clojure
// -------
//
// Setup:
//      Run `clojure` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      (Float/parseFloat "3.0")
//      ```
//
// Erlang
// ------
//
// Setup:
//      Run `erl` to enter the interpreter.
//
// Code:
//      ```text
//      io:format("~p~n", [3.0]).
//      string:to_float("3.0").
//      ```
//
// Elm
// ---
//
// Setup:
//      Run `elm repl` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      String.toFloat "3.0"
//      ```
//
// Scala
// -----
//
// Setup:
//      Run `scala` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      "3.0".toFloat
//      ```
//
// Elixir
// ------
//
// Setup:
//      Run `iex` to enter the interpreter.
//
// Code:
//      ```text
//      3.0;
//      String.to_float("3.0");
//      ```
//
// FORTRAN
// -------
//
// Setup:
//      Save to `main.f90` and run `gfortran -o main main.f90`
//
// Code:
//      ```text
//      program main
//        real :: x
//        character (len=30) :: word
//        word = "3."
//        read(word, *) x
//        print *, 3.
//        print *, x
//      end program main
//      ```
//
// D
// -
//
// Setup:
//      Save to `main.d` and run `dmd -run main.d`
//
// Code:
//      ```text
//      import std.conv;
//      import std.stdio;
//
//      void main()
//      {
//          writeln(3.0);
//          writeln(to!double("3.0"));
//      }
//      ```
//
// Coffeescript
// ------------
//
// Setup:
//      Run `coffee` to enter the interpreter.
//
// Code:
//      ```text
//      3.0;
//      parseFloat("3.0");
//      ```
//
// Cobol
// -----
//
// Setup:
//      Save to `main.cbl` and run `cobc main.cbl` then `cobcrun main`.
//
// Code:
//      ```text
//                IDENTIFICATION DIVISION.
//                PROGRAM-ID. main.
//
//                DATA DIVISION.
//                   WORKING-STORAGE SECTION.
//                   01 R PIC X(20)   VALUE "3.0".
//                   01 TOTAL        USAGE IS COMP-2.
//
//                PROCEDURE DIVISION.
//                   COMPUTE TOTAL = FUNCTION NUMVAL(R).
//                   Display 3.0.
//                   Display TOTAL.
//                   STOP RUN.
//      ```
//
// F#
// --
//
// Setup:
//      Run `fsharpi` to enter the interpreter.
//
// Code:
//      ```text
//      printfn "%f" 3.0;;
//      let f = float "3.0";;
//      printfn "%f" f;;
//      ```
//
// Visual Basic
// ------------
//
// Setup:
//      Save to `main.vb` and run `vbnc main.vb`.
//
// Code:
//      ```text
//      Imports System
//
//      Module Module1
//          Sub Main()
//              Console.WriteLine(Format$(3.0, "0.0000000000000"))
//              Console.WriteLine(Format$(CDbl("3.0"), "0.0000000000000"))
//          End Sub
//      End Module
//      ```
//
// OCaml
// -----
//
// Setup:
//      Save to `main.ml` and run `ocamlc -o main main.ml`.
//
// Code:
//      ```text
//      Printf.printf "%f\n" 3.0
//      let () =
//          let f = float_of_string "3.0" in
//          Printf.printf "%f\n" f
//      ```
//
// Objective-C
// -----------
//
// Setup:
//      Save to `main.m` and run `gcc -o main -lobjc -lgnustep-base main.m -fconstant-string-class=NSConstantString`.
//
// Code:
//      ```text
//      #import <Foundation/Foundation.h>
//      #import <stdio.h>
//
//      int main(int argv, char* argc[])
//      {
//          printf("%f\n", 3.0);
//          NSString *s = @"3.0";
//          double f = [s doubleValue];
//          printf("%f\n", f);
//      }
//      ```
//
// ReasonML
// --------
//
// Setup:
//      Run `rtop` to enter the interpreter.
//
// Code:
//      ```text
//      Printf.printf("%f\n", 3.0);
//      Printf.printf("%f\n", float_of_string("3.0"));
//      ```
//
// Zig
// ---
//
// Setup:
//      Save to `main.zig` and run `zig build-exe main.zig`
//
// Code:
//      ```text
//      const std = @import("std");
//
//      pub fn main() void {
//          const f: f64 = 3.0;
//          std.debug.warn("{}\n", f);
//          const x: f64 = std.fmt.parseFloat(f64, "3.0") catch unreachable;
//          std.debug.warn("{}\n", x);
//      }
//      ```
//
//
// Octave (and Matlab)
// -------------------
//
// Setup:
//      Run `octave` to enter the interpreter, or
//      run `octave --traditional` to enter the Matlab interpret.
//
// Code:
//      ```text
//      3.0
//      str2double("3.0")
//      ```
//
// Sage
// ----
//
// Setup:
//      Run `sage` to enter the interpreter.
//
// Code:
//      ```text
//      3.0
//      float("3.0")
//      ```
//
// JSON
// ----
//
// Setup:
//      Run `node` (or `nodejs`) to enter the JS interpreter.
//
// Code:
//      ```text
//      JSON.parse("3.0")
//      ```
//
// TOML
// ----
//
// Setup:
//      Run `python` to enter the Python interpreter.
//
// Code:
//      ```text
//      import tomlkit
//      tomlkit.parse("a = 3.0")
//      ```
//
// XML
// ---
//
// Setup:
//      Run `python` to enter the Python interpreter.
//
// Code:
//      ```text
//      from lxml import etree
//
//      def validate_xml(xsd, xml):
//          '''Validate XML file against schema'''
//
//          schema = etree.fromstring(xsd)
//          doc = etree.fromstring(xml)
//          xmlschema = etree.XMLSchema(schema)
//
//          return xmlschema.validate(doc)
//
//
//      xsd = b'''<?xml version="1.0" encoding="UTF-8"?>
//      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
//          <xs:element name="prize" type="xs:float"/>
//      </xs:schema>'''
//
//      xml = b'''<?xml version="1.0" encoding="UTF-8"?>
//      <prize>3.0</prize>
//      '''
//
//      validate_xml(xsd, xml)
//      ```
//
// SQLite
// ------
//
// Setup:
//      Run `sqlite3 :memory:` to enter the sqlite3 interpreter
//      with an in-memory database.
//
// Code:
//      ```text
//      CREATE TABLE stocks (price real);
//      INSERT INTO stocks VALUES (3.0);
//      SELECT * FROM stocks;
//      ```
//
// PostgreSQL
// ----------
//
// Setup:
//      Run `initdb -D db` to create a database data direction,
//      then run `pg_ctl -D db start` to start the server, then run
//      `createdb` to create a user database and `psql` to start the
//      interpreter.
//
// Code:
//      ```text
//      CREATE TABLE stocks (price real);
//      INSERT INTO stocks VALUES (3.0);
//      SELECT * FROM stocks;
//      ```
//
// MySQL
// -----
//
// Setup:
//      Run `mysqld` to start the server, then run `mysql` to start the
//      interpreter.
//
// Code:
//      ```text
//      USE mysql;
//      CREATE TABLE stocks (price real);
//      INSERT INTO stocks VALUES (3.0);
//      SELECT * FROM stocks;
//      ```
//
// MongoDB
// -------
//
// Setup:
//      Run `mongod --dbpath data/db` to start the server, then run
//      `mongo` to start the interpreter.
//
// Code:
//      ```text
//      use mydb
//      db.movie.insert({"name": 3.0})
//      db.movie.find()
//      ```

use super::config;

cfg_if! {
if #[cfg(not(feature = "format"))] {
    bitflags! {
        /// Dummy bitflags for the float format.
        #[doc(hidden)]
        #[derive(Default)]
        pub struct NumberFormat: u32 {
            const __NONEXHAUSTIVE = 0;
        }
    }

    impl NumberFormat {
        #[inline]
        pub fn standard() -> Option<NumberFormat> {
            Some(NumberFormat::default())
        }

        #[inline]
        pub fn digit_separator(&self) -> u8 {
            0
        }
    }
} else {
    // HELPERS

    // Determine if character is valid ASCII.
    #[inline]
    fn is_ascii(ch: u8) -> bool {
        ch.is_ascii()
    }

    /// Determine if the digit separator is valid.
    #[inline]
    #[cfg(not(feature = "radix"))]
    #[allow(unknown_lints, ellipsis_inclusive_range_patterns)]
    fn is_valid_separator(ch: u8) -> bool {
        match ch {
            b'0' ... b'9'       => false,
            b'+' | b'.' | b'-'  => false,
            _                   => (
                is_ascii(ch)
                && ch != config::get_exponent_default_char()
            )
        }
    }

    /// Determine if the digit separator is valid.
    #[inline]
    #[cfg(feature = "radix")]
    #[allow(unknown_lints, ellipsis_inclusive_range_patterns)]
    fn is_valid_separator(ch: u8) -> bool {
        match ch {
            b'A' ... b'Z'       => false,
            b'a' ... b'z'       => false,
            b'0' ... b'9'       => false,
            b'+' | b'.' | b'-'  => false,
            _                   => (
                is_ascii(ch)
                && ch != config::get_exponent_default_char()
                && ch != config::get_exponent_backup_char()
            )
        }
    }

    /// Convert digit separator to flags.
    macro_rules! digit_separator_to_flags {
        ($ch:expr) => {
            ($ch as u32) << 24
        };
    }

    /// Extract digit separator from flags.
    #[inline]
    fn digit_separator_from_flags(flag: u32) -> u8 {
        (flag >> 24) as u8
    }

    // BITFLAGS

    bitflags! {
        /// Bitflags for a serialized number format.
        ///
        /// This is used to derive the high-level bitflags.The default
        /// representation has no digit separators, no required integer or
        /// fraction digits, required exponent digits, and no digit separators.
        ///
        /// Bit Flags Layout
        /// ----------------
        ///
        /// The bitflags has the lower bits designated for flags that modify
        /// the parsing behavior of lexical, and the upper 8 bits set for the
        /// digit separator, allowing any valid ASCII character as a
        /// separator.
        ///
        /// ```text
        ///  0   1   2   3   4   5   6   7   8   9   0   1   2   3   4   5
        /// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        /// |I/R|F/R|E/R|+/M|R/M|e/e|+/E|R/E|e/F|S/S|S/C|I/I|F/I|E/I|I/L|F/L|
        /// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        ///
        ///  0   1   2   3   4   5   6   7   8   9   0   1   2   3   4   5
        /// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        /// |E/L|I/T|F/T|E/T|I/C|F/C|E/C|S/D|        Digit Separator        |
        /// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        ///
        /// Where:
        ///     I/R = Required integer digits.
        ///     F/R = Required fraction digits.
        ///     E/R = Required exponent digits.
        ///     +/M = No mantissa positive sign.
        ///     R/M = Required positive sign.
        ///     e/e = No exponent notation.
        ///     +/E = No exponent positive sign.
        ///     R/E = Required exponent sign.
        ///     e/F = No exponent without fraction.
        ///     S/S = No special (non-finite) values.
        ///     S/C = Case-sensitive special (non-finite) values.
        ///     I/I = Integer internal digit separator.
        ///     F/I = Fraction internal digit separator.
        ///     E/I = Exponent internal digit separator.
        ///     I/L = Integer leading digit separator.
        ///     F/L = Fraction leading digit separator.
        ///     E/L = Exponent leading digit separator.
        ///     I/T = Integer trailing digit separator.
        ///     F/T = Fraction trailing digit separator.
        ///     E/T = Exponent trailing digit separator.
        ///     I/C = Integer consecutive digit separator.
        ///     F/C = Fraction consecutive digit separator.
        ///     E/C = Exponent consecutive digit separator.
        ///     S/D = Special (non-finite) digit separator.
        /// ```
        ///
        /// Note:
        /// -----
        ///
        /// In order to limit the format specification and avoid parsing
        /// non-numerical data, all number formats require some significant
        /// digits. Examples of always invalid numbers include:
        /// - ``
        /// - `.`
        /// - `e`
        /// - `e7`
        ///
        /// Test Cases:
        /// -----------
        ///
        /// The following test-cases are used to define whether a literal or
        /// a string float is valid in a given language, and these tests are
        /// used to denote features in pre-defined formats. Only a few
        /// of these flags may modify the parsing behavior of integers.
        /// Integer parsing is assumed to be derived from float parsing,
        /// so if consecutive digit separators are valid in the integer
        /// component of a float, they are also valid in an integer.
        ///
        /// ```text
        /// 0: '.3'         // Non-required integer.
        /// 1: '3.'         // Non-required fraction.
        /// 2: '3e'         // Non-required exponent.
        /// 3. '+3.0'       // Mantissa positive sign.
        /// 4: '3.0e7'      // Exponent notation.
        /// 5: '3.0e+7'     // Exponent positive sign.
        /// 6. '3e7'        // Exponent notation without fraction.
        /// 7: 'NaN'        // Special (non-finite) values.
        /// 8: 'NAN'        // Case-sensitive special (non-finite) values.
        /// 9: '3_4.01'     // Integer internal digit separator.
        /// A: '3.0_1'      // Fraction internal digit separator.
        /// B: '3.0e7_1'    // Exponent internal digit separator.
        /// C: '_3.01'      // Integer leading digit separator.
        /// D: '3._01'      // Fraction leading digit separator.
        /// E: '3.0e_71'    // Exponent leading digit separator.
        /// F: '3_.01'      // Integer trailing digit separator.
        /// G: '3.01_'      // Fraction trailing digit separator.
        /// H: '3.0e71_'    // Exponent trailing digit separator.
        /// I: '3__4.01'    // Integer consecutive digit separator.
        /// J: '3.0__1'     // Fraction consecutive digit separator.
        /// K: '3.0e7__1'   // Exponent consecutive digit separator.
        /// L: 'In_f'       // Special (non-finite) digit separator.
        /// ```
        ///
        /// Currently Supported Programming and Data Languages:
        /// ---------------------------------------------------
        ///
        /// 1. Rust
        /// 2. Python
        /// 3. C++ (98, 03, 11, 14, 17)
        /// 4. C (89, 90, 99, 11, 18)
        /// 5. Ruby
        /// 6. Swift
        /// 7. Go
        /// 8. Haskell
        /// 9. Javascript
        /// 10. Perl
        /// 11. PHP
        /// 12. Java
        /// 13. R
        /// 14. Kotlin
        /// 15. Julia
        /// 16. C# (ISO-1, ISO-2, 3, 4, 5, 6, 7)
        /// 17. Kawa
        /// 18. Gambit-C
        /// 19. Guile
        /// 20. Clojure
        /// 21. Erlang
        /// 22. Elm
        /// 23. Scala
        /// 24. Elixir
        /// 25. FORTRAN
        /// 26. D
        /// 27. Coffeescript
        /// 28. Cobol
        /// 29. F#
        /// 30. Visual Basic
        /// 31. OCaml
        /// 32. Objective-C
        /// 33. ReasonML
        /// 34. Octave
        /// 35. Matlab
        /// 36. Zig
        /// 37. SageMath
        /// 38. JSON
        /// 39. TOML
        /// 40. XML
        /// 41. SQLite
        /// 42. PostgreSQL
        /// 43. MySQL
        /// 44. MongoDB
        #[derive(Default)]
        pub struct NumberFormat: u32 {
            // MASKS & FLAGS

            /// Mask to extract the flag bits.
            #[doc(hidden)]
            const FLAG_MASK                             = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::REQUIRED_MANTISSA_SIGN.bits
                | Self::NO_EXPONENT_NOTATION.bits
                | Self::NO_POSITIVE_EXPONENT_SIGN.bits
                | Self::REQUIRED_EXPONENT_SIGN.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::NO_SPECIAL.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::SPECIAL_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract the flag bits controlling interface parsing.
            ///
            /// This mask controls all the flags handled by the interface,
            /// omitting those that are handled prior. This limits the
            /// number of match paths required to determine the correct
            /// interface.
            const INTERFACE_FLAG_MASK                   = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_EXPONENT_NOTATION.bits
                | Self::NO_POSITIVE_EXPONENT_SIGN.bits
                | Self::REQUIRED_EXPONENT_SIGN.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract digit separator flags.
            #[doc(hidden)]
            const DIGIT_SEPARATOR_FLAG_MASK             = (
                Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::SPECIAL_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract integer digit separator flags.
            #[doc(hidden)]
            const INTEGER_DIGIT_SEPARATOR_FLAG_MASK     = (
                Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits
                | Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
                | Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract fraction digit separator flags.
            #[doc(hidden)]
            const FRACTION_DIGIT_SEPARATOR_FLAG_MASK     = (
                Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
                | Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract exponent digit separator flags.
            #[doc(hidden)]
            const EXPONENT_DIGIT_SEPARATOR_FLAG_MASK     = (
                Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            /// Mask to extract exponent flags.
            #[doc(hidden)]
            const EXPONENT_FLAG_MASK                    = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_POSITIVE_EXPONENT_SIGN.bits
                | Self::REQUIRED_EXPONENT_SIGN.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            /// Digits are required before the decimal point.
            #[doc(hidden)]
            const REQUIRED_INTEGER_DIGITS               = 0b000000000000000000000001;

            /// Digits are required after the decimal point.
            /// This check will only occur if the decimal point is present.
            #[doc(hidden)]
            const REQUIRED_FRACTION_DIGITS              = 0b000000000000000000000010;

            /// Digits are required after the exponent character.
            /// This check will only occur if the exponent character is present.
            #[doc(hidden)]
            const REQUIRED_EXPONENT_DIGITS              = 0b000000000000000000000100;

            /// Digits are required before or after the control characters.
            #[doc(hidden)]
            const REQUIRED_DIGITS                       = (
                Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
            );

            /// Positive sign before the mantissa is not allowed.
            #[doc(hidden)]
            const NO_POSITIVE_MANTISSA_SIGN             = 0b000000000000000000001000;

            /// Positive sign before the mantissa is required.
            #[doc(hidden)]
            const REQUIRED_MANTISSA_SIGN                = 0b000000000000000000010000;

            /// Exponent notation is not allowed.
            #[doc(hidden)]
            const NO_EXPONENT_NOTATION                  = 0b000000000000000000100000;

            /// Positive sign before the exponent is not allowed.
            #[doc(hidden)]
            const NO_POSITIVE_EXPONENT_SIGN             = 0b000000000000000001000000;

            /// Positive sign before the exponent is required.
            #[doc(hidden)]
            const REQUIRED_EXPONENT_SIGN                = 0b000000000000000010000000;

            /// Exponent without a fraction component is not allowed.
            ///
            /// This only checks if a decimal point precedes the exponent character.
            /// To require fraction digits or exponent digits with this check,
            /// please use the appropriate flags.
            #[doc(hidden)]
            const NO_EXPONENT_WITHOUT_FRACTION          = 0b000000000000000100000000;

            /// Special (non-finite) values are not allowed.
            #[doc(hidden)]
            const NO_SPECIAL                            = 0b000000000000001000000000;

            /// Special (non-finite) values are case-sensitive.
            #[doc(hidden)]
            const CASE_SENSITIVE_SPECIAL                = 0b000000000000010000000000;

            /// Digit separators are allowed between integer digits.
            #[doc(hidden)]
            const INTEGER_INTERNAL_DIGIT_SEPARATOR      = 0b000000000000100000000000;

            /// Digit separators are allowed between fraction digits.
            #[doc(hidden)]
            const FRACTION_INTERNAL_DIGIT_SEPARATOR     = 0b000000000001000000000000;

            /// Digit separators are allowed between exponent digits.
            #[doc(hidden)]
            const EXPONENT_INTERNAL_DIGIT_SEPARATOR     = 0b000000000010000000000000;

            /// Digit separators are allowed between digits.
            #[doc(hidden)]
            const INTERNAL_DIGIT_SEPARATOR              = (
                Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits
            );

            /// A digit separator is allowed before any integer digits.
            #[doc(hidden)]
            const INTEGER_LEADING_DIGIT_SEPARATOR       = 0b000000000100000000000000;

            /// A digit separator is allowed before any fraction digits.
            #[doc(hidden)]
            const FRACTION_LEADING_DIGIT_SEPARATOR      = 0b000000001000000000000000;

            /// A digit separator is allowed before any exponent digits.
            #[doc(hidden)]
            const EXPONENT_LEADING_DIGIT_SEPARATOR      = 0b000000010000000000000000;

            /// A digit separator is allowed before any digits.
            #[doc(hidden)]
            const LEADING_DIGIT_SEPARATOR               = (
                Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
            );

            /// A digit separator is allowed after any integer digits.
            #[doc(hidden)]
            const INTEGER_TRAILING_DIGIT_SEPARATOR      = 0b000000100000000000000000;

            /// A digit separator is allowed after any fraction digits.
            #[doc(hidden)]
            const FRACTION_TRAILING_DIGIT_SEPARATOR     = 0b000001000000000000000000;

            /// A digit separator is allowed after any exponent digits.
            #[doc(hidden)]
            const EXPONENT_TRAILING_DIGIT_SEPARATOR     = 0b000010000000000000000000;

            /// A digit separator is allowed after any digits.
            #[doc(hidden)]
            const TRAILING_DIGIT_SEPARATOR              = (
                Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
                | Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits
            );

            /// Multiple consecutive integer digit separators are allowed.
            #[doc(hidden)]
            const INTEGER_CONSECUTIVE_DIGIT_SEPARATOR   = 0b000100000000000000000000;

            /// Multiple consecutive fraction digit separators are allowed.
            #[doc(hidden)]
            const FRACTION_CONSECUTIVE_DIGIT_SEPARATOR  = 0b001000000000000000000000;

            /// Multiple consecutive exponent digit separators are allowed.
            #[doc(hidden)]
            const EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR  = 0b010000000000000000000000;

            /// Any digit separators are allowed in special (non-finite) values.
            #[doc(hidden)]
            const SPECIAL_DIGIT_SEPARATOR               = 0b100000000000000000000000;

            /// Multiple consecutive digit separators are allowed.
            #[doc(hidden)]
            const CONSECUTIVE_DIGIT_SEPARATOR           = (
                Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // PRE-DEFINED
            //
            // Sample Format Shorthand:
            // ------------------------
            //
            // The format shorthand lists the test cases, and if applicable,
            // the digit separator character. For example, the shorthand
            // `[134-_]` specifies it passes tests 1, 3, and 4, and uses
            // `'_'` as a digit-separator character. Meanwhile, `[0]` means it
            // passes test 0, and has no digit separator.

            // RUST LITERAL [4569ABFGHIJK-_]
            /// Float format for a Rust literal floating-point number.
            const RUST_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // RUST STRING [0134567]
            /// Float format to parse a Rust float from string.
            const RUST_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // RUST STRING STRICT [01345678]
            /// `RUST_STRING`, but enforces strict equality for special values.
            const RUST_STRING_STRICT = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // PYTHON LITERAL [013456]
            /// Float format for a Python literal floating-point number.
            const PYTHON_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // PYTHON STRING [0134567]
            /// Float format to parse a Python float from string.
            const PYTHON_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C++17 LITERAL [01345689AB-']
            /// Float format for a C++17 literal floating-point number.
            const CXX17_LITERAL = (
                digit_separator_to_flags!(b'\'')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // C++17 STRING [013456]
            const CXX17_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C++14 LITERAL [01345689AB-']
            /// Float format for a C++14 literal floating-point number.
            const CXX14_LITERAL = (
                digit_separator_to_flags!(b'\'')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // C++14 STRING [013456]
            /// Float format to parse a C++14 float from string.
            const CXX14_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C++11 LITERAL [0134568]
            /// Float format for a C++11 literal floating-point number.
            const CXX11_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // C++11 STRING [013456]
            /// Float format to parse a C++11 float from string.
            const CXX11_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C++03 LITERAL [0134567]
            /// Float format for a C++03 literal floating-point number.
            const CXX03_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // C++03 STRING [013456]
            /// Float format to parse a C++03 float from string.
            const CXX03_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C++98 LITERAL [0134567]
            /// Float format for a C++98 literal floating-point number.
            const CXX98_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // C++98 STRING [013456]
            /// Float format to parse a C++98 float from string.
            const CXX98_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C18 LITERAL [0134568]
            /// Float format for a C18 literal floating-point number.
            const C18_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // C18 STRING [013456]
            /// Float format to parse a C18 float from string.
            const C18_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C11 LITERAL [0134568]
            /// Float format for a C11 literal floating-point number.
            const C11_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // C11 STRING [013456]
            /// Float format to parse a C11 float from string.
            const C11_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C99 LITERAL [0134568]
            /// Float format for a C99 literal floating-point number.
            const C99_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // C99 STRING [013456]
            /// Float format to parse a C99 float from string.
            const C99_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C90 LITERAL [0134567]
            /// Float format for a C90 literal floating-point number.
            const C90_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // C90 STRING [013456]
            /// Float format to parse a C90 float from string.
            const C90_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // C89 LITERAL [0134567]
            /// Float format for a C89 literal floating-point number.
            const C89_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // C89 STRING [013456]
            /// Float format to parse a C89 float from string.
            const C89_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // RUBY LITERAL [345689A-_]
            /// Float format for a Ruby literal floating-point number.
            const RUBY_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // RUBY STRING [01234569AB-_]
            /// Float format to parse a Ruby float from string.
            // Note: Amazingly, Ruby 1.8+ do not allow parsing special values.
            const RUBY_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // SWIFT LITERAL [34569ABFGHIJK-_]
            /// Float format for a Swift literal floating-point number.
            const SWIFT_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // SWIFT STRING [13456]
            /// Float format to parse a Swift float from string.
            const SWIFT_STRING = Self::REQUIRED_FRACTION_DIGITS.bits;

            // GO LITERAL [0134567]
            /// Float format for a Golang literal floating-point number.
            const GO_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // GO STRING [013456]
            /// Float format to parse a Golang float from string.
            const GO_STRING = Self::REQUIRED_FRACTION_DIGITS.bits;

            // HASKELL LITERAL [456]
            /// Float format for a Haskell literal floating-point number.
            const HASKELL_LITERAL = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::NO_SPECIAL.bits
            );

            // HASKELL STRING [45678]
            /// Float format to parse a Haskell float from string.
            const HASKELL_STRING = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // JAVASCRIPT LITERAL [01345678]
            /// Float format for a Javascript literal floating-point number.
            const JAVASCRIPT_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // JAVASCRIPT STRING [012345678]
            /// Float format to parse a Javascript float from string.
            const JAVASCRIPT_STRING = Self::CASE_SENSITIVE_SPECIAL.bits;

            // PERL LITERAL [0134569ABDEFGHIJK-_]
            /// Float format for a Perl literal floating-point number.
            const PERL_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // PERL STRING [01234567]
            /// Float format to parse a Perl float from string.
            const PERL_STRING = 0;

            // PHP LITERAL [01345678]
            /// Float format for a PHP literal floating-point number.
            const PHP_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // PHP STRING [0123456]
            /// Float format to parse a PHP float from string.
            const PHP_STRING = Self::NO_SPECIAL.bits;

            // JAVA LITERAL [0134569ABIJK-_]
            /// Float format for a Java literal floating-point number.
            const JAVA_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // JAVA STRING [01345678]
            /// Float format to parse a Java float from string.
            const JAVA_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // R LITERAL [01345678]
            /// Float format for a R literal floating-point number.
            const R_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // R STRING [01234567]
            /// Float format to parse a R float from string.
            const R_STRING = 0;

            // KOTLIN LITERAL [0134569ABIJK-_]
            /// Float format for a Kotlin literal floating-point number.
            const KOTLIN_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // KOTLIN STRING [0134568]
            /// Float format to parse a Kotlin float from string.
            const KOTLIN_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // JULIA LITERAL [01345689A-_]
            /// Float format for a Julia literal floating-point number.
            const JULIA_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
            );

            // JULIA STRING [01345678]
            /// Float format to parse a Julia float from string.
            const JULIA_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // CSHARP7 LITERAL [034569ABIJK-_]
            /// Float format for a C#7 literal floating-point number.
            const CSHARP7_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // CSHARP7 STRING [0134568]
            /// Float format to parse a C#7 float from string.
            const CSHARP7_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP6 LITERAL [03456]
            /// Float format for a C#6 literal floating-point number.
            const CSHARP6_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP6 STRING [0134568]
            /// Float format to parse a C#6 float from string.
            const CSHARP6_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP5 LITERAL [03456]
            /// Float format for a C#5 literal floating-point number.
            const CSHARP5_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP5 STRING [0134568]
            /// Float format to parse a C#5 float from string.
            const CSHARP5_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP4 LITERAL [03456]
            /// Float format for a C#4 literal floating-point number.
            const CSHARP4_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP4 STRING [0134568]
            /// Float format to parse a C#4 float from string.
            const CSHARP4_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP3 LITERAL [03456]
            /// Float format for a C#3 literal floating-point number.
            const CSHARP3_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP3 STRING [0134568]
            /// Float format to parse a C#3 float from string.
            const CSHARP3_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP2 LITERAL [03456]
            /// Float format for a C#2 literal floating-point number.
            const CSHARP2_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP2 STRING [0134568]
            /// Float format to parse a C#2 float from string.
            const CSHARP2_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // CSHARP1 LITERAL [03456]
            /// Float format for a C#1 literal floating-point number.
            const CSHARP1_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CSHARP1 STRING [0134568]
            /// Float format to parse a C#1 float from string.
            const CSHARP1_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // KAWA LITERAL [013456]
            /// Float format for a Kawa literal floating-point number.
            const KAWA_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // KAWA STRING [013456]
            /// Float format to parse a Kawa float from string.
            const KAWA_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // GAMBITC LITERAL [013456]
            /// Float format for a Gambit-C literal floating-point number.
            const GAMBITC_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // GAMBITC STRING [013456]
            /// Float format to parse a Gambit-C float from string.
            const GAMBITC_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // GUILE LITERAL [013456]
            /// Float format for a Guile literal floating-point number.
            const GUILE_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // GUILE STRING [013456]
            /// Float format to parse a Guile float from string.
            const GUILE_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CLOJURE LITERAL [13456]
            /// Float format for a Clojure literal floating-point number.
            const CLOJURE_LITERAL = (
                Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // CLOJURE STRING [01345678]
            /// Float format to parse a Clojure float from string.
            const CLOJURE_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // ERLANG LITERAL [34578]
            /// Float format for an Erlang literal floating-point number.
            const ERLANG_LITERAL = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // ERLANG STRING [345]
            /// Float format to parse an Erlang float from string.
            const ERLANG_STRING = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::NO_SPECIAL.bits
            );

            // ELM LITERAL [456]
            /// Float format for an Elm literal floating-point number.
            const ELM_LITERAL = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
            );

            // ELM STRING [01345678]
            /// Float format to parse an Elm float from string.
            // Note: There is no valid representation of NaN, just Infinity.
            const ELM_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // SCALA LITERAL [3456]
            /// Float format for a Scala literal floating-point number.
            const SCALA_LITERAL = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // SCALA STRING [01345678]
            /// Float format to parse a Scala float from string.
            const SCALA_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // ELIXIR LITERAL [3459AB-_]
            /// Float format for an Elixir literal floating-point number.
            const ELIXIR_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_DIGITS.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // ELIXIR STRING [345]
            /// Float format to parse an Elixir float from string.
            const ELIXIR_STRING = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::NO_SPECIAL.bits
            );

            // FORTRAN LITERAL [013456]
            /// Float format for a FORTRAN literal floating-point number.
            const FORTRAN_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // FORTRAN STRING [0134567]
            /// Float format to parse a FORTRAN float from string.
            const FORTRAN_STRING = Self::REQUIRED_EXPONENT_DIGITS.bits;

            // D LITERAL [0134569ABFGHIJK-_]
            /// Float format for a D literal floating-point number.
            const D_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // D STRING [01345679AFG-_]
            /// Float format to parse a D float from string.
            const D_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits
                | Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits
                | Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits
            );

            // COFFEESCRIPT LITERAL [01345678]
            /// Float format for a Coffeescript literal floating-point number.
            const COFFEESCRIPT_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // COFFEESCRIPT STRING [012345678]
            /// Float format to parse a Coffeescript float from string.
            const COFFEESCRIPT_STRING = Self::CASE_SENSITIVE_SPECIAL.bits;

            // COBOL LITERAL [0345]
            /// Float format for a Cobol literal floating-point number.
            const COBOL_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_EXPONENT_WITHOUT_FRACTION.bits
                | Self::NO_SPECIAL.bits
            );

            // COBOL STRING [012356]
            /// Float format to parse a Cobol float from string.
            const COBOL_STRING = (
                Self::REQUIRED_EXPONENT_SIGN.bits
                | Self::NO_SPECIAL.bits
            );

            // FSHARP LITERAL [13456789ABIJK-_]
            /// Float format for a F# literal floating-point number.
            const FSHARP_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // FSHARP STRING [013456789ABCDEFGHIJKL-_]
            /// Float format to parse a F# float from string.
            const FSHARP_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::SPECIAL_DIGIT_SEPARATOR.bits
            );

            // VB LITERAL [03456]
            /// Float format for a Visual Basic literal floating-point number.
            const VB_LITERAL = (
                Self::REQUIRED_FRACTION_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // VB STRING [01345678]
            /// Float format to parse a Visual Basic float from string.
            // Note: To my knowledge, Visual Basic cannot parse infinity.
            const VB_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // OCAML LITERAL [1456789ABDFGHIJK-_]
            /// Float format for an OCaml literal floating-point number.
            const OCAML_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // OCAML STRING [01345679ABCDEFGHIJKL-_]
            /// Float format to parse an OCaml float from string.
            const OCAML_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::SPECIAL_DIGIT_SEPARATOR.bits
            );

            // OBJECTIVEC LITERAL [013456]
            /// Float format for an Objective-C literal floating-point number.
            const OBJECTIVEC_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // OBJECTIVEC STRING [013456]
            /// Float format to parse an Objective-C float from string.
            const OBJECTIVEC_STRING = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // REASONML LITERAL [13456789ABDFGHIJK-_]
            /// Float format for a ReasonML literal floating-point number.
            const REASONML_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // REASONML STRING [01345679ABCDEFGHIJKL-_]
            /// Float format to parse a ReasonML float from string.
            const REASONML_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
                | Self::SPECIAL_DIGIT_SEPARATOR.bits
            );

            // OCTAVE LITERAL [013456789ABDFGHIJK-_]
            /// Float format for an Octave literal floating-point number.
            // Note: Octave accepts both NaN and nan, Inf and inf.
            const OCTAVE_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // OCTAVE STRING [01345679ABCDEFGHIJK-,]
            /// Float format to parse an Octave float from string.
            const OCTAVE_STRING = (
                digit_separator_to_flags!(b',')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // MATLAB LITERAL [013456789ABDFGHIJK-_]
            /// Float format for an Matlab literal floating-point number.
            // Note: Matlab accepts both NaN and nan, Inf and inf.
            const MATLAB_LITERAL = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // MATLAB STRING [01345679ABCDEFGHIJK-,]
            /// Float format to parse an Matlab float from string.
            const MATLAB_STRING = (
                digit_separator_to_flags!(b',')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
                | Self::LEADING_DIGIT_SEPARATOR.bits
                | Self::TRAILING_DIGIT_SEPARATOR.bits
                | Self::CONSECUTIVE_DIGIT_SEPARATOR.bits
            );

            // ZIG LITERAL [1456]
            /// Float format for a Zig literal floating-point number.
            const ZIG_LITERAL = (
                Self::REQUIRED_INTEGER_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::NO_SPECIAL.bits
            );

            // ZIG STRING [01234567]
            /// Float format to parse a Zig float from string.
            const ZIG_STRING = 0;

            // SAGE LITERAL [012345678]
            /// Float format for a Sage literal floating-point number.
            // Note: Both Infinity and infinity are accepted.
            const SAGE_LITERAL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // SAGE STRING [01345679AB-_]
            /// Float format to parse a Sage float from string.
            const SAGE_STRING = (
                digit_separator_to_flags!(b'_')
                | Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // JSON [456]
            /// Float format for a JSON literal floating-point number.
            const JSON = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_POSITIVE_MANTISSA_SIGN.bits
                | Self::NO_SPECIAL.bits
            );

            // TOML [34569AB]
            /// Float format for a TOML literal floating-point number.
            const TOML = (
                Self::REQUIRED_DIGITS.bits
                | Self::NO_SPECIAL.bits
                | Self::INTERNAL_DIGIT_SEPARATOR.bits
            );

            // YAML (defined in-terms of JSON schema).
            /// Float format for a YAML literal floating-point number.
            const YAML = Self::JSON.bits;

            // XML [01234578]
            /// Float format for a XML literal floating-point number.
            const XML = Self::CASE_SENSITIVE_SPECIAL.bits;

            // SQLITE [013456]
            /// Float format for a SQLite literal floating-point number.
            const SQLITE = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // POSTGRESQL [013456]
            /// Float format for a PostgreSQL literal floating-point number.
            const POSTGRESQL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // MYSQL [013456]
            /// Float format for a MySQL literal floating-point number.
            const MYSQL = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::NO_SPECIAL.bits
            );

            // MONGODB [01345678]
            /// Float format for a MongoDB literal floating-point number.
            const MONGODB = (
                Self::REQUIRED_EXPONENT_DIGITS.bits
                | Self::CASE_SENSITIVE_SPECIAL.bits
            );

            // HIDDEN DEFAULTS

            /// Float format when no flags are set.
            #[doc(hidden)]
            const PERMISSIVE = 0;

            /// Permissive interface float format flags.
            #[doc(hidden)]
            const PERMISSIVE_INTERFACE = Self::PERMISSIVE.bits & Self::INTERFACE_FLAG_MASK.bits;

            /// Standard float format.
            #[doc(hidden)]
            const STANDARD = Self::RUST_STRING.bits;

            /// Standard interface float format flags.
            #[doc(hidden)]
            const STANDARD_INTERFACE = Self::STANDARD.bits & Self::INTERFACE_FLAG_MASK.bits;

            /// Float format when all digit separator flags are set.
            #[doc(hidden)]
            const IGNORE = Self::DIGIT_SEPARATOR_FLAG_MASK.bits;

            /// Ignore interface float format flags.
            #[doc(hidden)]
            const IGNORE_INTERFACE = Self::IGNORE.bits & Self::INTERFACE_FLAG_MASK.bits;

            // HIDDEN FLAGS

            // Early versions of Rustc, such as 1.24.0, do not have const fn.
            // We need these flags to be evaluated in a const manner.
            #[doc(hidden)]
            const INTEGER_I = Self::INTEGER_INTERNAL_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const INTEGER_L = Self::INTEGER_LEADING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const INTEGER_T = Self::INTEGER_TRAILING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const INTEGER_C = Self::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const INTEGER_IL = Self::INTEGER_I.bits | Self::INTEGER_L.bits;

            #[doc(hidden)]
            const INTEGER_IT = Self::INTEGER_I.bits | Self::INTEGER_T.bits;

            #[doc(hidden)]
            const INTEGER_LT = Self::INTEGER_L.bits | Self::INTEGER_T.bits;

            #[doc(hidden)]
            const INTEGER_ILT = Self::INTEGER_IL.bits | Self::INTEGER_T.bits;

            #[doc(hidden)]
            const INTEGER_IC = Self::INTEGER_I.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_LC = Self::INTEGER_L.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_TC = Self::INTEGER_T.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_ILC = Self::INTEGER_IL.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_ITC = Self::INTEGER_IT.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_LTC = Self::INTEGER_LT.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const INTEGER_ILTC = Self::INTEGER_ILT.bits | Self::INTEGER_C.bits;

            #[doc(hidden)]
            const FRACTION_I = Self::FRACTION_INTERNAL_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const FRACTION_L = Self::FRACTION_LEADING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const FRACTION_T = Self::FRACTION_TRAILING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const FRACTION_C = Self::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const FRACTION_IL = Self::FRACTION_I.bits | Self::FRACTION_L.bits;

            #[doc(hidden)]
            const FRACTION_IT = Self::FRACTION_I.bits | Self::FRACTION_T.bits;

            #[doc(hidden)]
            const FRACTION_LT = Self::FRACTION_L.bits | Self::FRACTION_T.bits;

            #[doc(hidden)]
            const FRACTION_ILT = Self::FRACTION_IL.bits | Self::FRACTION_T.bits;

            #[doc(hidden)]
            const FRACTION_IC = Self::FRACTION_I.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_LC = Self::FRACTION_L.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_TC = Self::FRACTION_T.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_ILC = Self::FRACTION_IL.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_ITC = Self::FRACTION_IT.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_LTC = Self::FRACTION_LT.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const FRACTION_ILTC = Self::FRACTION_ILT.bits | Self::FRACTION_C.bits;

            #[doc(hidden)]
            const EXPONENT_I = Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const EXPONENT_L = Self::EXPONENT_LEADING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const EXPONENT_T = Self::EXPONENT_TRAILING_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const EXPONENT_C = Self::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR.bits;

            #[doc(hidden)]
            const EXPONENT_IL = Self::EXPONENT_I.bits | Self::EXPONENT_L.bits;

            #[doc(hidden)]
            const EXPONENT_IT = Self::EXPONENT_I.bits | Self::EXPONENT_T.bits;

            #[doc(hidden)]
            const EXPONENT_LT = Self::EXPONENT_L.bits | Self::EXPONENT_T.bits;

            #[doc(hidden)]
            const EXPONENT_ILT = Self::EXPONENT_IL.bits | Self::EXPONENT_T.bits;

            #[doc(hidden)]
            const EXPONENT_IC = Self::EXPONENT_I.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_LC = Self::EXPONENT_L.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_TC = Self::EXPONENT_T.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_ILC = Self::EXPONENT_IL.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_ITC = Self::EXPONENT_IT.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_LTC = Self::EXPONENT_LT.bits | Self::EXPONENT_C.bits;

            #[doc(hidden)]
            const EXPONENT_ILTC = Self::EXPONENT_ILT.bits | Self::EXPONENT_C.bits;
        }
    }

    // Ensure all our bit flags are valid.
    macro_rules! check_subsequent_flags {
        ($name:ident; $x:ident, $y:ident) => (
            const_assert!($name; NumberFormat::$x.bits << 1 == NumberFormat::$y.bits);
        );
    }
    check_subsequent_flags!(flags0; REQUIRED_INTEGER_DIGITS, REQUIRED_FRACTION_DIGITS);
    check_subsequent_flags!(flags1; REQUIRED_FRACTION_DIGITS, REQUIRED_EXPONENT_DIGITS);
    check_subsequent_flags!(flags2; REQUIRED_EXPONENT_DIGITS, NO_POSITIVE_MANTISSA_SIGN);
    check_subsequent_flags!(flags3; NO_POSITIVE_MANTISSA_SIGN, REQUIRED_MANTISSA_SIGN);
    check_subsequent_flags!(flags4; REQUIRED_MANTISSA_SIGN, NO_EXPONENT_NOTATION);
    check_subsequent_flags!(flags5; NO_EXPONENT_NOTATION, NO_POSITIVE_EXPONENT_SIGN);
    check_subsequent_flags!(flags6; NO_POSITIVE_EXPONENT_SIGN, REQUIRED_EXPONENT_SIGN);
    check_subsequent_flags!(flags7; REQUIRED_EXPONENT_SIGN, NO_EXPONENT_WITHOUT_FRACTION);
    check_subsequent_flags!(flags8; NO_EXPONENT_WITHOUT_FRACTION, NO_SPECIAL);
    check_subsequent_flags!(flags9; NO_SPECIAL, CASE_SENSITIVE_SPECIAL);
    check_subsequent_flags!(flags10; CASE_SENSITIVE_SPECIAL, INTEGER_INTERNAL_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags11; INTEGER_INTERNAL_DIGIT_SEPARATOR, FRACTION_INTERNAL_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags12; FRACTION_INTERNAL_DIGIT_SEPARATOR, EXPONENT_INTERNAL_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags13; EXPONENT_INTERNAL_DIGIT_SEPARATOR, INTEGER_LEADING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags14; INTEGER_LEADING_DIGIT_SEPARATOR, FRACTION_LEADING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags15; FRACTION_LEADING_DIGIT_SEPARATOR, EXPONENT_LEADING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags16; EXPONENT_LEADING_DIGIT_SEPARATOR, INTEGER_TRAILING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags17; INTEGER_TRAILING_DIGIT_SEPARATOR, FRACTION_TRAILING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags18; FRACTION_TRAILING_DIGIT_SEPARATOR, EXPONENT_TRAILING_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags19; EXPONENT_TRAILING_DIGIT_SEPARATOR, INTEGER_CONSECUTIVE_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags20; INTEGER_CONSECUTIVE_DIGIT_SEPARATOR, FRACTION_CONSECUTIVE_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags21; FRACTION_CONSECUTIVE_DIGIT_SEPARATOR, EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR);
    check_subsequent_flags!(flags22; EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR, SPECIAL_DIGIT_SEPARATOR);

    /// Add flag to flags
    macro_rules! add_flag {
        ($flags:ident, $bool:ident, $flag:ident) => {
            if $bool {
                $flags |= NumberFormat::$flag;
            }
        };
    }

    impl NumberFormat {
        /// Compile float format value from specifications.
        ///
        /// * `digit_separator`                         - Character to separate digits.
        /// * `required_integer_digits`                 - If digits are required before the decimal point.
        /// * `required_fraction_digits`                - If digits are required after the decimal point.
        /// * `required_exponent_digits`                - If digits are required after the exponent character.
        /// * `no_positive_mantissa_sign`               - If positive sign before the mantissa is not allowed.
        /// * `required_mantissa_sign`                  - If positive sign before the mantissa is required.
        /// * `no_exponent_notation`                    - If exponent notation is not allowed.
        /// * `no_positive_exponent_sign`               - If positive sign before the exponent is not allowed.
        /// * `required_exponent_sign`                  - If sign before the exponent is required.
        /// * `no_exponent_without_fraction`            - If exponent without fraction is not allowed.
        /// * `no_special`                              - If special (non-finite) values are not allowed.
        /// * `case_sensitive_special`                  - If special (non-finite) values are case-sensitive.
        /// * `integer_internal_digit_separator`        - If digit separators are allowed between integer digits.
        /// * `fraction_internal_digit_separator`       - If digit separators are allowed between fraction digits.
        /// * `exponent_internal_digit_separator`       - If digit separators are allowed between exponent digits.
        /// * `integer_leading_digit_separator`         - If a digit separator is allowed before any integer digits.
        /// * `fraction_leading_digit_separator`        - If a digit separator is allowed before any fraction digits.
        /// * `exponent_leading_digit_separator`        - If a digit separator is allowed before any exponent digits.
        /// * `integer_trailing_digit_separator`        - If a digit separator is allowed after any integer digits.
        /// * `fraction_trailing_digit_separator`       - If a digit separator is allowed after any fraction digits.
        /// * `exponent_trailing_digit_separator`       - If a digit separator is allowed after any exponent digits.
        /// * `integer_consecutive_digit_separator`     - If multiple consecutive integer digit separators are allowed.
        /// * `fraction_consecutive_digit_separator`    - If multiple consecutive fraction digit separators are allowed.
        /// * `special_digit_separator`                 - If any digit separators are allowed in special (non-finite) values.
        ///
        /// Returns the value if it was able to compile the format,
        /// otherwise, returns None.
        #[cfg_attr(feature = "radix", doc = " Digit separators must not be in the character group `[A-Za-z0-9+.-]`, nor be equal to")]
        #[cfg_attr(feature = "radix", doc = " [`get_exponent_default_char`](fn.get_exponent_default_char.html) or")]
        #[cfg_attr(feature = "radix", doc = " [`get_exponent_backup_char`](fn.get_exponent_backup_char.html).")]
        #[cfg_attr(not(feature = "radix"), doc = " Digit separators must not be in the character group `[0-9+.-]`, nor be equal to")]
        #[cfg_attr(not(feature = "radix"), doc = " [get_exponent_default_char](fn.get_exponent_default_char.html).")]
        #[inline]
        pub fn compile(
            digit_separator: u8,
            required_integer_digits: bool,
            required_fraction_digits: bool,
            required_exponent_digits: bool,
            no_positive_mantissa_sign: bool,
            required_mantissa_sign: bool,
            no_exponent_notation: bool,
            no_positive_exponent_sign: bool,
            required_exponent_sign: bool,
            no_exponent_without_fraction: bool,
            no_special: bool,
            case_sensitive_special: bool,
            integer_internal_digit_separator: bool,
            fraction_internal_digit_separator: bool,
            exponent_internal_digit_separator: bool,
            integer_leading_digit_separator: bool,
            fraction_leading_digit_separator: bool,
            exponent_leading_digit_separator: bool,
            integer_trailing_digit_separator: bool,
            fraction_trailing_digit_separator: bool,
            exponent_trailing_digit_separator: bool,
            integer_consecutive_digit_separator: bool,
            fraction_consecutive_digit_separator: bool,
            exponent_consecutive_digit_separator: bool,
            special_digit_separator: bool
        ) -> Option<NumberFormat> {
            let mut format = NumberFormat::default();
            // Generic flags.
            add_flag!(format, required_integer_digits, REQUIRED_INTEGER_DIGITS);
            add_flag!(format, required_fraction_digits, REQUIRED_FRACTION_DIGITS);
            add_flag!(format, required_exponent_digits, REQUIRED_EXPONENT_DIGITS);
            add_flag!(format, no_positive_mantissa_sign, NO_POSITIVE_MANTISSA_SIGN);
            add_flag!(format, required_mantissa_sign, REQUIRED_MANTISSA_SIGN);
            add_flag!(format, no_exponent_notation, NO_EXPONENT_NOTATION);
            add_flag!(format, no_positive_exponent_sign, NO_POSITIVE_EXPONENT_SIGN);
            add_flag!(format, required_exponent_sign, REQUIRED_EXPONENT_SIGN);
            add_flag!(format, no_exponent_without_fraction, NO_EXPONENT_WITHOUT_FRACTION);
            add_flag!(format, no_special, NO_SPECIAL);
            add_flag!(format, case_sensitive_special, CASE_SENSITIVE_SPECIAL);

            // Digit separator flags.
            add_flag!(format, integer_internal_digit_separator, INTEGER_INTERNAL_DIGIT_SEPARATOR);
            add_flag!(format, fraction_internal_digit_separator, FRACTION_INTERNAL_DIGIT_SEPARATOR);
            add_flag!(format, exponent_internal_digit_separator, EXPONENT_INTERNAL_DIGIT_SEPARATOR);
            add_flag!(format, integer_leading_digit_separator, INTEGER_LEADING_DIGIT_SEPARATOR);
            add_flag!(format, fraction_leading_digit_separator, FRACTION_LEADING_DIGIT_SEPARATOR);
            add_flag!(format, exponent_leading_digit_separator, EXPONENT_LEADING_DIGIT_SEPARATOR);
            add_flag!(format, integer_trailing_digit_separator, INTEGER_TRAILING_DIGIT_SEPARATOR);
            add_flag!(format, fraction_trailing_digit_separator, FRACTION_TRAILING_DIGIT_SEPARATOR);
            add_flag!(format, exponent_trailing_digit_separator, EXPONENT_TRAILING_DIGIT_SEPARATOR);
            add_flag!(format, integer_consecutive_digit_separator, INTEGER_CONSECUTIVE_DIGIT_SEPARATOR);
            add_flag!(format, fraction_consecutive_digit_separator, FRACTION_CONSECUTIVE_DIGIT_SEPARATOR);
            add_flag!(format, exponent_consecutive_digit_separator, EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR);
            add_flag!(format, special_digit_separator, SPECIAL_DIGIT_SEPARATOR);

            // Digit separator.
            if format.intersects(NumberFormat::DIGIT_SEPARATOR_FLAG_MASK) {
                format.bits |= digit_separator_to_flags!(digit_separator);
            }

            // Validation.
            let is_invalid =
                !is_valid_separator(digit_separator)
                || format.intersects(NumberFormat::NO_EXPONENT_NOTATION) && format.intersects(NumberFormat::EXPONENT_FLAG_MASK)
                || no_positive_mantissa_sign && required_mantissa_sign
                || no_positive_exponent_sign && required_exponent_sign
                || no_special && (case_sensitive_special || special_digit_separator)
                || format & NumberFormat::INTEGER_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR
                || format & NumberFormat::FRACTION_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR
                || format & NumberFormat::EXPONENT_DIGIT_SEPARATOR_FLAG_MASK == NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR;
            match is_invalid {
                true  => None,
                false => Some(format)
            }
        }

        /// Compile permissive number format.
        ///
        /// The permissive number format does not require any control
        /// grammar, besides the presence of mantissa digits.
        ///
        /// This function cannot fail, but returns an option for consistency
        /// with other grammar compilers.
        pub fn permissive() -> Option<NumberFormat> {
            Some(NumberFormat::PERMISSIVE)
        }

        /// Compile standard number format.
        ///
        /// The standard number format is guaranteed to be identical
        /// to the format expected by Rust's string to number parsers.
        ///
        /// This function cannot fail, but returns an option for consistency
        /// with other grammar compilers.
        pub fn standard() -> Option<NumberFormat> {
            Some(NumberFormat::STANDARD)
        }

        /// Compile ignore number format.
        ///
        /// The ignore number format ignores all digit separators,
        /// and is permissive for all other control grammar, so
        /// implements a fast parser.
        ///
        /// * `digit_separator`                         - Character to separate digits.
        ///
        /// Returns the value if it was able to compile the format,
        /// otherwise, returns None.
        pub fn ignore(digit_separator: u8) -> Option<NumberFormat> {
            if !is_valid_separator(digit_separator) {
                return None
            }

            let mut format = NumberFormat::IGNORE;
            format.bits |= digit_separator_to_flags!(digit_separator);

            Some(format)
        }

        /// Create float format directly from digit separator for unittests.
        #[cfg(test)]
        #[inline]
        pub(crate) fn from_separator(digit_separator: u8) -> NumberFormat {
            NumberFormat { bits: digit_separator_to_flags!(digit_separator) }
        }

        /// Get the flag bits from the compiled float format.
        #[inline]
        pub fn flags(self) -> NumberFormat {
            return self & NumberFormat::FLAG_MASK
        }

        /// Get the interface flag bits from the compiled float format.
        #[inline]
        pub(crate) fn interface_flags(self) -> NumberFormat {
            return self & NumberFormat::INTERFACE_FLAG_MASK
        }

        /// Get the digit separator from the compiled float format.
        #[inline]
        pub fn digit_separator(self) -> u8 {
            digit_separator_from_flags(self.bits)
        }

        /// Get if digits are required before the decimal point.
        #[inline]
        pub fn required_integer_digits(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_INTEGER_DIGITS)
        }

        /// Get if digits are required after the decimal point.
        #[inline]
        pub fn required_fraction_digits(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_FRACTION_DIGITS)
        }

        /// Get if digits are required after the exponent character.
        #[inline]
        pub fn required_exponent_digits(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_EXPONENT_DIGITS)
        }

        /// Get if digits are required before or after the decimal point.
        #[inline]
        pub fn required_digits(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_DIGITS)
        }

        /// Get if positive sign before the mantissa is not allowed.
        #[inline]
        pub fn no_positive_mantissa_sign(self) -> bool {
            self.intersects(NumberFormat::NO_POSITIVE_MANTISSA_SIGN)
        }

        /// Get if positive sign before the mantissa is required.
        #[inline]
        pub fn required_mantissa_sign(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_MANTISSA_SIGN)
        }

        /// Get if exponent notation is not allowed.
        #[inline]
        pub fn no_exponent_notation(self) -> bool {
            self.intersects(NumberFormat::NO_EXPONENT_NOTATION)
        }

        /// Get if positive sign before the exponent is not allowed.
        #[inline]
        pub fn no_positive_exponent_sign(self) -> bool {
            self.intersects(NumberFormat::NO_POSITIVE_EXPONENT_SIGN)
        }

        /// Get if sign before the exponent is required.
        #[inline]
        pub fn required_exponent_sign(self) -> bool {
            self.intersects(NumberFormat::REQUIRED_EXPONENT_SIGN)
        }

        /// Get if exponent without fraction is not allowed.
        #[inline]
        pub fn no_exponent_without_fraction(self) -> bool {
            self.intersects(NumberFormat::NO_EXPONENT_WITHOUT_FRACTION)
        }

        /// Get if special (non-finite) values are not allowed.
        #[inline]
        pub fn no_special(self) -> bool {
            self.intersects(NumberFormat::NO_SPECIAL)
        }

        /// Get if special (non-finite) values are case-sensitive.
        #[inline]
        pub fn case_sensitive_special(self) -> bool {
            self.intersects(NumberFormat::CASE_SENSITIVE_SPECIAL)
        }

        /// Get if digit separators are allowed between integer digits.
        #[inline]
        pub fn integer_internal_digit_separator(self) -> bool {
            self.intersects(NumberFormat::INTEGER_INTERNAL_DIGIT_SEPARATOR)
        }

        /// Get if digit separators are allowed between fraction digits.
        #[inline]
        pub fn fraction_internal_digit_separator(self) -> bool {
            self.intersects(NumberFormat::FRACTION_INTERNAL_DIGIT_SEPARATOR)
        }

        /// Get if digit separators are allowed between exponent digits.
        #[inline]
        pub fn exponent_internal_digit_separator(self) -> bool {
            self.intersects(NumberFormat::EXPONENT_INTERNAL_DIGIT_SEPARATOR)
        }

        /// Get if digit separators are allowed between digits.
        #[inline]
        pub fn internal_digit_separator(self) -> bool {
            self.intersects(NumberFormat::INTERNAL_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed before any integer digits.
        #[inline]
        pub fn integer_leading_digit_separator(self) -> bool {
            self.intersects(NumberFormat::INTEGER_LEADING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed before any fraction digits.
        #[inline]
        pub fn fraction_leading_digit_separator(self) -> bool {
            self.intersects(NumberFormat::FRACTION_LEADING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed before any exponent digits.
        #[inline]
        pub fn exponent_leading_digit_separator(self) -> bool {
            self.intersects(NumberFormat::EXPONENT_LEADING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed before any digits.
        #[inline]
        pub fn leading_digit_separator(self) -> bool {
            self.intersects(NumberFormat::LEADING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed after any integer digits.
        #[inline]
        pub fn integer_trailing_digit_separator(self) -> bool {
            self.intersects(NumberFormat::INTEGER_TRAILING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed after any fraction digits.
        #[inline]
        pub fn fraction_trailing_digit_separator(self) -> bool {
            self.intersects(NumberFormat::FRACTION_TRAILING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed after any exponent digits.
        #[inline]
        pub fn exponent_trailing_digit_separator(self) -> bool {
            self.intersects(NumberFormat::EXPONENT_TRAILING_DIGIT_SEPARATOR)
        }

        /// Get if a digit separator is allowed after any digits.
        #[inline]
        pub fn trailing_digit_separator(self) -> bool {
            self.intersects(NumberFormat::TRAILING_DIGIT_SEPARATOR)
        }

        /// Get if multiple consecutive integer digit separators are allowed.
        #[inline]
        pub fn integer_consecutive_digit_separator(self) -> bool {
            self.intersects(NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR)
        }

        /// Get if multiple consecutive fraction digit separators are allowed.
        #[inline]
        pub fn fraction_consecutive_digit_separator(self) -> bool {
            self.intersects(NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR)
        }

        /// Get if multiple consecutive exponent digit separators are allowed.
        #[inline]
        pub fn exponent_consecutive_digit_separator(self) -> bool {
            self.intersects(NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR)
        }

        /// Get if multiple consecutive digit separators are allowed.
        #[inline]
        pub fn consecutive_digit_separator(self) -> bool {
            self.intersects(NumberFormat::CONSECUTIVE_DIGIT_SEPARATOR)
        }

        /// Get if any digit separators are allowed in special (non-finite) values.
        #[inline]
        pub fn special_digit_separator(self) -> bool {
            self.intersects(NumberFormat::SPECIAL_DIGIT_SEPARATOR)
        }
    }

    // TESTS
    // -----

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn test_is_valid_separator() {
            assert_eq!(is_valid_separator(b'_'), true);
            assert_eq!(is_valid_separator(b'\''), true);
            assert_eq!(is_valid_separator(b'0'), false);
            assert_eq!(is_valid_separator(128), false);
        }

        #[test]
        fn test_compile() {
            // Test all false
            let flags = NumberFormat::compile(b'_', false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false).unwrap();
            assert_eq!(flags.flags(), NumberFormat::default());
            assert_eq!(flags.digit_separator(), 0);
        }

        #[test]
        fn test_permissive() {
            let flags = NumberFormat::ignore(b'_').unwrap();
            assert_eq!(flags.flags(), NumberFormat::DIGIT_SEPARATOR_FLAG_MASK);
        }

        #[test]
        fn test_ignore() {
            let flags = NumberFormat::ignore(b'_').unwrap();
            assert_eq!(flags.flags(), NumberFormat::DIGIT_SEPARATOR_FLAG_MASK);
            assert_eq!(flags.digit_separator(), b'_');
            assert_eq!(flags.required_integer_digits(), false);
            assert_eq!(flags.required_fraction_digits(), false);
            assert_eq!(flags.required_exponent_digits(), false);
            assert_eq!(flags.required_digits(), false);
            assert_eq!(flags.no_positive_mantissa_sign(), false);
            assert_eq!(flags.required_mantissa_sign(), false);
            assert_eq!(flags.no_exponent_notation(), false);
            assert_eq!(flags.no_positive_exponent_sign(), false);
            assert_eq!(flags.required_exponent_sign(), false);
            assert_eq!(flags.no_exponent_without_fraction(), false);
            assert_eq!(flags.no_special(), false);
            assert_eq!(flags.case_sensitive_special(), false);
            assert_eq!(flags.integer_internal_digit_separator(), true);
            assert_eq!(flags.fraction_internal_digit_separator(), true);
            assert_eq!(flags.exponent_internal_digit_separator(), true);
            assert_eq!(flags.internal_digit_separator(), true);
            assert_eq!(flags.integer_leading_digit_separator(), true);
            assert_eq!(flags.fraction_leading_digit_separator(), true);
            assert_eq!(flags.exponent_leading_digit_separator(), true);
            assert_eq!(flags.leading_digit_separator(), true);
            assert_eq!(flags.integer_trailing_digit_separator(), true);
            assert_eq!(flags.fraction_trailing_digit_separator(), true);
            assert_eq!(flags.exponent_trailing_digit_separator(), true);
            assert_eq!(flags.trailing_digit_separator(), true);
            assert_eq!(flags.integer_consecutive_digit_separator(), true);
            assert_eq!(flags.fraction_consecutive_digit_separator(), true);
            assert_eq!(flags.exponent_consecutive_digit_separator(), true);
            assert_eq!(flags.consecutive_digit_separator(), true);
            assert_eq!(flags.special_digit_separator(), true);
        }

        #[test]
        fn test_flags() {
            let flags = [
                NumberFormat::REQUIRED_INTEGER_DIGITS,
                NumberFormat::REQUIRED_FRACTION_DIGITS,
                NumberFormat::REQUIRED_EXPONENT_DIGITS,
                NumberFormat::NO_POSITIVE_MANTISSA_SIGN,
                NumberFormat::REQUIRED_MANTISSA_SIGN,
                NumberFormat::NO_EXPONENT_NOTATION,
                NumberFormat::NO_POSITIVE_EXPONENT_SIGN,
                NumberFormat::REQUIRED_EXPONENT_SIGN,
                NumberFormat::NO_EXPONENT_WITHOUT_FRACTION,
                NumberFormat::NO_SPECIAL,
                NumberFormat::CASE_SENSITIVE_SPECIAL,
                NumberFormat::INTEGER_INTERNAL_DIGIT_SEPARATOR,
                NumberFormat::FRACTION_INTERNAL_DIGIT_SEPARATOR,
                NumberFormat::EXPONENT_INTERNAL_DIGIT_SEPARATOR,
                NumberFormat::INTEGER_LEADING_DIGIT_SEPARATOR,
                NumberFormat::FRACTION_LEADING_DIGIT_SEPARATOR,
                NumberFormat::EXPONENT_LEADING_DIGIT_SEPARATOR,
                NumberFormat::INTEGER_TRAILING_DIGIT_SEPARATOR,
                NumberFormat::FRACTION_TRAILING_DIGIT_SEPARATOR,
                NumberFormat::EXPONENT_TRAILING_DIGIT_SEPARATOR,
                NumberFormat::INTEGER_CONSECUTIVE_DIGIT_SEPARATOR,
                NumberFormat::FRACTION_CONSECUTIVE_DIGIT_SEPARATOR,
                NumberFormat::EXPONENT_CONSECUTIVE_DIGIT_SEPARATOR,
                NumberFormat::SPECIAL_DIGIT_SEPARATOR
            ];
            for &flag in flags.iter() {
                assert_eq!(flag.flags(), flag);
                assert_eq!(flag.digit_separator(), 0);
            }
        }

        #[test]
        fn test_constants() {
            let flags = [
                NumberFormat::RUST_LITERAL,
                NumberFormat::RUST_STRING,
                NumberFormat::RUST_STRING_STRICT,
                NumberFormat::PYTHON_LITERAL,
                NumberFormat::PYTHON_STRING,
                NumberFormat::CXX17_LITERAL,
                NumberFormat::CXX17_STRING,
                NumberFormat::CXX14_LITERAL,
                NumberFormat::CXX14_STRING,
                NumberFormat::CXX11_LITERAL,
                NumberFormat::CXX11_STRING,
                NumberFormat::CXX03_LITERAL,
                NumberFormat::CXX03_STRING,
                NumberFormat::CXX98_LITERAL,
                NumberFormat::CXX98_STRING,
                NumberFormat::C18_LITERAL,
                NumberFormat::C18_STRING,
                NumberFormat::C11_LITERAL,
                NumberFormat::C11_STRING,
                NumberFormat::C99_LITERAL,
                NumberFormat::C99_STRING,
                NumberFormat::C90_LITERAL,
                NumberFormat::C90_STRING,
                NumberFormat::C89_LITERAL,
                NumberFormat::C89_STRING,
                NumberFormat::RUBY_LITERAL,
                NumberFormat::RUBY_STRING,
                NumberFormat::SWIFT_LITERAL,
                NumberFormat::SWIFT_STRING,
                NumberFormat::GO_LITERAL,
                NumberFormat::GO_STRING,
                NumberFormat::HASKELL_LITERAL,
                NumberFormat::HASKELL_STRING,
                NumberFormat::JAVASCRIPT_LITERAL,
                NumberFormat::JAVASCRIPT_STRING,
                NumberFormat::PERL_LITERAL,
                NumberFormat::PERL_STRING,
                NumberFormat::PHP_LITERAL,
                NumberFormat::PHP_STRING,
                NumberFormat::JAVA_LITERAL,
                NumberFormat::JAVA_STRING,
                NumberFormat::R_LITERAL,
                NumberFormat::R_STRING,
                NumberFormat::KOTLIN_LITERAL,
                NumberFormat::KOTLIN_STRING,
                NumberFormat::JULIA_LITERAL,
                NumberFormat::JULIA_STRING,
                NumberFormat::CSHARP7_LITERAL,
                NumberFormat::CSHARP7_STRING,
                NumberFormat::CSHARP6_LITERAL,
                NumberFormat::CSHARP6_STRING,
                NumberFormat::CSHARP5_LITERAL,
                NumberFormat::CSHARP5_STRING,
                NumberFormat::CSHARP4_LITERAL,
                NumberFormat::CSHARP4_STRING,
                NumberFormat::CSHARP3_LITERAL,
                NumberFormat::CSHARP3_STRING,
                NumberFormat::CSHARP2_LITERAL,
                NumberFormat::CSHARP2_STRING,
                NumberFormat::CSHARP1_LITERAL,
                NumberFormat::CSHARP1_STRING,
                NumberFormat::KAWA_LITERAL,
                NumberFormat::KAWA_STRING,
                NumberFormat::GAMBITC_LITERAL,
                NumberFormat::GAMBITC_STRING,
                NumberFormat::GUILE_LITERAL,
                NumberFormat::GUILE_STRING,
                NumberFormat::CLOJURE_LITERAL,
                NumberFormat::CLOJURE_STRING,
                NumberFormat::ERLANG_LITERAL,
                NumberFormat::ERLANG_STRING,
                NumberFormat::ELM_LITERAL,
                NumberFormat::ELM_STRING,
                NumberFormat::SCALA_LITERAL,
                NumberFormat::SCALA_STRING,
                NumberFormat::ELIXIR_LITERAL,
                NumberFormat::ELIXIR_STRING,
                NumberFormat::FORTRAN_LITERAL,
                NumberFormat::FORTRAN_STRING,
                NumberFormat::D_LITERAL,
                NumberFormat::D_STRING,
                NumberFormat::COFFEESCRIPT_LITERAL,
                NumberFormat::COFFEESCRIPT_STRING,
                NumberFormat::COBOL_LITERAL,
                NumberFormat::COBOL_STRING,
                NumberFormat::FSHARP_LITERAL,
                NumberFormat::FSHARP_STRING,
                NumberFormat::VB_LITERAL,
                NumberFormat::VB_STRING,
                NumberFormat::OCAML_LITERAL,
                NumberFormat::OCAML_STRING,
                NumberFormat::OBJECTIVEC_LITERAL,
                NumberFormat::OBJECTIVEC_STRING,
                NumberFormat::REASONML_LITERAL,
                NumberFormat::REASONML_STRING,
                NumberFormat::OCTAVE_LITERAL,
                NumberFormat::OCTAVE_STRING,
                NumberFormat::MATLAB_LITERAL,
                NumberFormat::MATLAB_STRING,
                NumberFormat::ZIG_LITERAL,
                NumberFormat::ZIG_STRING,
                NumberFormat::SAGE_LITERAL,
                NumberFormat::SAGE_STRING,
                NumberFormat::JSON,
                NumberFormat::TOML,
                NumberFormat::YAML,
                NumberFormat::XML,
                NumberFormat::SQLITE,
                NumberFormat::POSTGRESQL,
                NumberFormat::MYSQL,
                NumberFormat::MONGODB
            ];
            for &flag in flags.iter() {
                // Just wanna check the flags are defined.
                assert!((flag.bits == 0) | true);
                assert!((flag.digit_separator() == 0) | true);
            }
        }
    }
}}   // cfg_if