ratio.qbk
86.2 KB
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
[/
/ Copyright (c) 2008 Howard Hinnant
/ Copyright (c) 2006, 2008 Beman Dawes
/ Copyright (c) 2009-2011 Vicente J. Botet Escriba
/
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
/]
[library Boost.Ratio
[quickbook 1.5]
[version 2.1.0]
[authors [Hinnant, Howard]]
[authors [Dawes, Beman]]
[authors [Botet Escriba, Vicente J.]]
[copyright 2008 Howard Hinnant]
[copyright 2006, 2008 Beman Dawes]
[copyright 2009-2012 Vicente J. Botet Escriba]
[category math]
[id ratio]
[dirname ratio]
[purpose
Compile time rational arithmetic.
]
[license
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
[@http://www.boost.org/LICENSE_1_0.txt])
]
]
[/==================]
[def __Boost_Ratio [*Boost.Ratio]]
[/===============================================]
[def __time_point `time_point`]
[def __hours `hours`]
[/===============================================]
[def __ratio [link ratio.reference.std.ratio_hpp.ratio `ratio`]]
[template ratio_conf[link_text] [link ratio.reference.std.ratio_hpp.conf [link_text]]]
[def __BOOST_RATIO_USES_STATIC_ASSERT [link ratio.reference.config_hpp.assert `BOOST_RATIO_USES_STATIC_ASSERT`]]
[def __BOOST_RATIO_USES_MPL_ASSERT [link ratio.reference.config_hpp.assert `BOOST_RATIO_USES_MPL_ASSERT`]]
[def __BOOST_RATIO_USES_ARRAY_ASSERT [link ratio.reference.config_hpp.assert `BOOST_RATIO_USES_ARRAY_ASSERT`]]
[def __BOOST_RATIO_EXTENSIONS [link ratio.reference.config_hpp.ext `BOOST_RATIO_EXTENSIONS`]]
[def __BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0 [link ratio.reference.config_hpp.deprecated `BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0`]]
[def __BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0 [link ratio.reference.config_hpp.deprecated `BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0 `]]
[def __BOOST_RATIO_VERSION [link ratio.reference.config_hpp.version `BOOST_RATIO_VERSION `]]
[template ratio_arithmetic[link_text] [link ratio.reference.std.ratio_hpp.ratio_arithmetic [link_text]]]
[def __ratio_add [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_add`]]
[def __ratio_subtract [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_subtract`]]
[def __ratio_multiply [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_multiply`]]
[def __ratio_divide [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_divide`]]
[def __ratio_power [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_power`]]
[def __ratio_negate [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_negate`]]
[def __ratio_abs [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_abs`]]
[def __ratio_sign [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_sign`]]
[def __ratio_gcd [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_gcd`]]
[def __ratio_lcm [link ratio.reference.std.ratio_hpp.ratio_arithmetic `ratio_lcm`]]
[template ratio_comparison[link_text] [link ratio.reference.std.ratio_hpp.ratio_comparison [link_text]]]
[def __ratio_equal [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_equal`]]
[def __ratio_not_equal [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_not_equal`]]
[def __ratio_less [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_less`]]
[def __ratio_less_equal [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_less_equal`]]
[def __ratio_greater [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_greater`]]
[def __ratio_greater_equal [link ratio.reference.std.ratio_hpp.ratio_comparison `ratio_greater_equal`]]
[template ratio_si_typedefs[link_text] [link ratio.reference.std.ratio_hpp.ratio_si_typedefs [link_text]]]
[def __atto [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `atto`]]
[def __femto [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `femto`]]
[def __pico [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `pico`]]
[def __nano [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `nano`]]
[def __micro [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `micro`]]
[def __milli [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `milli`]]
[def __centi [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `centi`]]
[def __deci [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `deci`]]
[def __deca [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `deca`]]
[def __hecto [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `hecto`]]
[def __kilo [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `kilo`]]
[def __mega [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `mega`]]
[def __giga [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `giga`]]
[def __tera [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `tera`]]
[def __peta [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `peta`]]
[def __exa [link ratio.reference.std.ratio_hpp.ratio_si_typedefs `exa`]]
[def __kibi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `kibi`]]
[def __mebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `mebi`]]
[def __gibi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `gibi`]]
[def __tebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `tebi`]]
[def __pebi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `pebi`]]
[def __exbi [link ratio.reference.std.ratio_hpp.ratio_iec_typedefs `exbi`]]
[template mu[]'''μ'''] [/ µ Greek small letter mu]
[def __Rational_Constant [link ratio.reference.mpl.rational_constant Rational Constant]]
[/warning Ratio is not part of the Boost libraries.]
[/===============]
[section Overview]
[/===============]
[/====================================]
[heading How to Use This Documentation]
[/====================================]
This documentation makes use of the following naming and formatting conventions.
* Code is in `fixed width font` and is syntax-highlighted.
* Replaceable text that you will need to supply is in [~italics].
* Free functions are rendered in the code font followed by `()`, as in `free_function()`.
* If a name refers to a class template, it is specified like this: `class_template<>`; that is, it is in code font and its name is followed by `<>` to indicate that it is a class template.
* If a name refers to a function-like macro, it is specified like this: `MACRO()`;
that is, it is uppercase in code font and its name is followed by `()` to indicate that it is a function-like macro. Object-like macros appear without the trailing `()`.
* Names that refer to /concepts/ in the generic programming sense are specified in CamelCase.
[note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
Finally, you can mentally add the following to any code fragments in this document:
// Include all of Ratio files
#include <boost/ratio.hpp>
using namespace boost;
[/=================]
[section Motivation]
[/=================]
__Boost_Ratio aims to implement the compile time ratio facility in C++0x, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]. That document provides background and motivation for key design decisions and is the source of a good deal of information in this documentation.
[endsect]
[/==================]
[section Description]
[/==================]
The __Boost_Ratio library provides:
* A class template, __ratio, for specifying compile time rational constants such as 1/3 of a nanosecond or the number of inches per meter. __ratio represents a compile time ratio of compile time constants with support for compile time arithmetic with overflow and division by zero protection.
* It provides a textual representation of `boost::ratio<N, D>` in the form of a `std::basic_string` which can be useful for I/O.
* Some extension related to the __Rational_Constant concept enabling the use of __ratio<> in the context of [*Boost.MPL] numeric metafunctions.
[endsect]
[endsect]
[/==============================]
[section:users_guide User's Guide]
[/==============================]
[/======================================]
[section:getting_started Getting Started]
[/======================================]
[/======================================]
[section:install Installing Ratio]
[/======================================]
[/=================================]
[heading Getting Boost.Ratio ]
[/=================================]
Boost.Ratio is in the latest Boost release in the folder `/boost/ratio`. Documentation, tests and examples folder are at `boost/libs/ratio/`.
You can also access the latest (unstable?) state from the [@http://svn.boost.org/svn/boost/trunk Boost trunk] directories `boost/ratio` and `libs/ratio`.
Just go to [@http://svn.boost.org/trac/boost/wiki/BoostSubversion the wiki] and follow the instructions there for anonymous SVN access.
[/==========================================]
[heading Where to install Boost.Ratio? ]
[/==========================================]
The simple way is to decompress (or checkout from SVN) the files in your BOOST_ROOT directory.
[/=================================]
[heading Building Boost.Ratio ]
[/=================================]
__Boost_Ratio is a header only library, so no need to compile anything, you just need to `include <boost/ratio.hpp>`.
[/===================]
[heading Requirements]
[/===================]
__Boost_Ratio depends on some Boost libraries. For these specific parts you must use either Boost version 1.39.0 or later (even older versions may work).
In particular, __Boost_Ratio depends on:
[variablelist
[
[[@http://www.boost.org/libs/config [*Boost.Config]]] [for configuration purposes, ...]
]
[
[[@http://www.boost.org/libs/integer [*Boost.Integer]]] [for cstdint conformance, and integer traits ...]
]
[
[[@http://www.boost.org/libs/mpl [*Boost.MPL]]] [for MPL Assert and bool, logical ...]
]
[
[[@http://www.boost.org/libs/static_assert [*Boost.StaticAssert]]] [for STATIC_ASSERT, ...]
]
[
[[@http://www.boost.org/libs/type_traits [*Boost.TypeTraits]]] [for is_base, is_convertible ...]
]
[
[[@http://www.boost.org/libs/utility [*Boost.Utility/EnableIf]]] [for enable_if, ...]
]
]
[/=========================================================]
[heading Building an executable that uses __Boost_Ratio ]
[/=========================================================]
No link is needed.
[/=========================]
[heading Exception safety ]
[/=========================]
All functions in the library are exception-neutral, providing the strong exception safety guarantee.
[/=====================]
[heading Thread safety ]
[/=====================]
All functions in the library are thread-unsafe except when noted explicitly.
[/========================]
[heading Tested compilers ]
[/========================]
__Boost_Ratio should work with an C++03 conforming compiler. The current version has been tested on:
Windows with
* MSVC 10.0
MinGW with
* GCC 4.5.0
* GCC 4.5.0 -std=c++0x
* GCC 4.5.2
* GCC 4.5.2 -std=c++0x
* GCC 4.6.0
* GCC 4.6.0 -std=c++0x
Ubuntu with
* GCC 4.4.6
* GCC 4.4.6 -std=c++0x
* GCC 4.5.4
* GCC 4.5.4 -std=c++0x
* GCC 4.6.1
* GCC 4.6.1 -std=c++0x
* Intel 12.1.3
* Intel 12.1.3 -std=c++0x
OsX with
* GCC 4.1.2
* GCC 4.6.2
* GCC 4.6.2 -std=c++0x
* GCC 4.7.0
* GCC 4.7.0 -std=c++0x
* GCC 4.7.1
* GCC 4.7.1 -std=c++0x
* clang 1.6
* clang 2.9
* clang 2.9 -std=c++0x
* clang 3.0
* clang 3.0 -std=c++0x
* clang 3.1
* clang 3.1 -std=c++0x
* clang 3.1 -std=c++0x -stdlib=libc++
* clang 3.2
* clang 3.2 -std=c++11
* clang 3.2 -std=c++11 -stdlib=libc++
[note Please let us know how this works on other platforms/compilers.]
[note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
[endsect]
[endsect]
[section Tutorial]
[heading Ratio]
__ratio is a general purpose utility inspired by Walter Brown allowing one to easily and safely compute rational values at compile-time. The __ratio class catches all errors (such as divide by zero and overflow) at compile time. It is used in the duration and __time_point classes to efficiently create units of time. It can also be used in other "quantity" libraries or anywhere there is a rational constant which is known at compile-time. The use of this utility can greatly reduce the chances of run-time overflow because the __ratio (and any ratios resulting from __ratio arithmetic) are always reduced to the lowest terms.
__ratio is a template taking two `intmax_ts`, with the second defaulted to 1. In addition to copy constructors and assignment, it only has two public members, both of which are `static const intmax_t`. One is the numerator of the __ratio and the other is the denominator. The __ratio is always normalized such that it is expressed in lowest terms, and the denominator is always positive. When the numerator is 0, the denominator is always 1.
[*Example:]
typedef __ratio<5, 3> five_thirds;
// five_thirds::num == 5, five_thirds::den == 3
typedef __ratio<25, 15> also_five_thirds;
// also_five_thirds::num == 5, also_five_thirds::den == 3
typedef ratio_divide<five_thirds, also_five_thirds>::type one;
// one::num == 1, one::den == 1
This facility also includes convenience typedefs for the SI prefixes __atto through __exa corresponding to their internationally recognized definitions (in terms of __ratio). This is a tremendous syntactic convenience. It will prevent errors in specifying constants as one no longer has to double count the number of zeros when trying to write millions or billions.
[*Example:]
typedef ratio_multiply<__ratio<5>, giga>::type _5giga;
// _5giga::num == 5000000000, _5giga::den == 1
typedef ratio_multiply<__ratio<5>, nano>::type _5nano;
// _5nano::num == 1, _5nano::den == 200000000
[heading Ratio I/O]
For each `ratio<N, D>` there exists a `ratio_string<ratio<N, D>, CharT>` for which you can query two strings: `symbol` and `prefix`. For those `ratio`'s that correspond to an [@http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes SI prefix] prefix corresponds to the internationally recognized prefix, stored as a `basic_string<CharT>`. For example `ratio_string<mega, char>::prefix()` returns `string("mega")`. For those `ratio`s that correspond to an [@http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes SI prefix] `symbol` corresponds to the internationally recognized symbol, stored as a `basic_string<CharT>`. For example, `ratio_string<mega, char>::symbol()` returns `string("M")`. For all other `ratio`s, both `prefix()` and `symbol()` return a `basic_string` containing "[`ratio::num/ratio::den`]".
`ratio_string<ratio<N, D>, CharT>` is only defined for four character types:
* `char`: UTF-8
* `char16_t`: UTF-16
* `char32_t`: UTF-32
* `wchar_t`: UTF-16 (if wchar_t is 16 bits) or UTF-32
When the character is char, UTF-8 will be used to encode the names. When the character is `char16_t`, UTF-16 will be used to encode the names. When the character is `char32_t`, UTF-32 will be used to encode the names. When the character is `wchar_t`, the encoding will be UTF-16 if `wchar_t` is 16 bits, and otherwise UTF-32.
The `symbol` (Greek mu or [mu]) for micro is defined by [@http://www.unicode.org/charts/PDF/U0080.pdf Unicode] to be U+00B5.
[*Examples:]
#include <boost/ratio/ratio_io.hpp>
#include <iostream>
int main()
{
using namespace std;
using namespace boost;
cout << "ratio_string<deca, char>::prefix() = "
<< ratio_string<deca, char>::prefix() << '\n';
cout << "ratio_string<deca, char>::symbol() = "
<< ratio_string<deca, char>::symbol() << '\n';
cout << "ratio_string<giga, char>::prefix() = "
<< ratio_string<giga, char>::prefix() << '\n';
cout << "ratio_string<giga, char>::symbol() = "
<< ratio_string<giga, char>::symbol() << '\n';
cout << "ratio_string<ratio<4, 6>, char>::prefix() = "
<< ratio_string<ratio<4, 6>, char>::prefix() << '\n';
cout << "ratio_string<ratio<4, 6>, char>::symbol() = "
<< ratio_string<ratio<4, 6>, char>::symbol() << '\n';
}
The output will be
ratio_string<deca, char>::prefix() = deca
ratio_string<deca, char>::symbol() = da
ratio_string<giga, char>::prefix() = giga
ratio_string<giga, char>::symbol() = G
ratio_string<ratio<4, 6>, char>::prefix() = [2/3]
ratio_string<ratio<4, 6>, char>::symbol() = [2/3]
[heading Ratio MPL Numeric Metafunctions]
With the view of the _ratio class as a __Rational_Constant we can mix _ratio<> and [*Boost.MPL] Integral Constants in the same expression, as in
typedef mpl::times<int_<5>, giga>::type _5giga;
// _5giga::num == 5000000000, _5giga::den == 1
typedef mpl::times<int_<5>, nano>::type _5nano;
// _5nano::num == 1, _5nano::den == 200000000
[endsect]
[/===============]
[section:Examples Example]
[/===============]
[/===============]
[section SI units]
[/===============]
This example illustrates the use of type-safe physics code interoperating with `boost::chrono::duration` types, taking advantage of the __Boost_Ratio infrastructure and design philosophy.
Let's start by defining a `length` class template that mimics `boost::chrono::duration`, which represents a time duration in various units, but restricts the representation to `double` and uses __Boost_Ratio for length unit conversions:
template <class Ratio>
class length {
private:
double len_;
public:
typedef Ratio ratio;
length() : len_(1) {}
length(const double& len) : len_(len) {}
template <class R>
length(const length<R>& d)
: len_(d.count() * boost::ratio_divide<Ratio, R>::type::den /
boost::ratio_divide<Ratio, R>::type::num) {}
double count() const {return len_;}
length& operator+=(const length& d) {len_ += d.count(); return *this;}
length& operator-=(const length& d) {len_ -= d.count(); return *this;}
length operator+() const {return *this;}
length operator-() const {return length(-len_);}
length& operator*=(double rhs) {len_ *= rhs; return *this;}
length& operator/=(double rhs) {len_ /= rhs; return *this;}
};
Here's a small sampling of length units:
typedef length<boost::__ratio<1> > meter; // set meter as "unity"
typedef length<boost::__centi> centimeter; // 1/100 meter
typedef length<boost::__kilo> kilometer; // 1000 meters
typedef length<boost::__ratio<254, 10000> > inch; // 254/10000 meters
Note that since `length`'s template parameter is actually a generic ratio type, so we can use boost::ratio allowing for more complex length units:
typedef length<boost::ratio_multiply<boost::__ratio<12>, inch::__ratio>::type> foot; // 12 inchs
typedef length<boost::ratio_multiply<boost::__ratio<5280>, foot::__ratio>::type> mile; // 5280 feet
Now we need a floating point-based definition of seconds:
typedef boost::chrono::duration<double> seconds; // unity
We can even support sub-nanosecond durations:
typedef boost::chrono::duration<double, boost::__pico> picosecond; // 10^-12 seconds
typedef boost::chrono::duration<double, boost::__femto> femtosecond; // 10^-15 seconds
typedef boost::chrono::duration<double, boost::__atto> attosecond; // 10^-18 seconds
Finally, we can write a proof-of-concept of an SI units library, hard-wired for meters and floating point seconds, though it will accept other units:
template <class R1, class R2>
class quantity
{
double q_;
public:
typedef R1 time_dim;
typedef R2 distance_dim;
quantity() : q_(1) {}
double get() const {return q_;}
void set(double q) {q_ = q;}
};
template <>
class quantity<boost::__ratio<1>, boost::__ratio<0> >
{
double q_;
public:
quantity() : q_(1) {}
quantity(seconds d) : q_(d.count()) {} // note: only User1::seconds needed here
double get() const {return q_;}
void set(double q) {q_ = q;}
};
template <>
class quantity<boost::__ratio<0>, boost::__ratio<1> >
{
double q_;
public:
quantity() : q_(1) {}
quantity(meter d) : q_(d.count()) {} // note: only User1::meter needed here
double get() const {return q_;}
void set(double q) {q_ = q;}
};
template <>
class quantity<boost::__ratio<0>, boost::__ratio<0> >
{
double q_;
public:
quantity() : q_(1) {}
quantity(double d) : q_(d) {}
double get() const {return q_;}
void set(double q) {q_ = q;}
};
That allows us to create some useful SI-based unit types:
typedef quantity<boost::__ratio<0>, boost::__ratio<0> > Scalar;
typedef quantity<boost::__ratio<1>, boost::__ratio<0> > Time; // second
typedef quantity<boost::__ratio<0>, boost::__ratio<1> > Distance; // meter
typedef quantity<boost::__ratio<-1>, boost::__ratio<1> > Speed; // meter/second
typedef quantity<boost::__ratio<-2>, boost::__ratio<1> > Acceleration; // meter/second^2
To make quantity useful, we need to be able to do arithmetic:
template <class R1, class R2, class R3, class R4>
quantity<typename boost::ratio_subtract<R1, R3>::type,
typename boost::ratio_subtract<R2, R4>::type>
operator/(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
{
typedef quantity<typename boost::ratio_subtract<R1, R3>::type,
typename boost::ratio_subtract<R2, R4>::type> R;
R r;
r.set(x.get() / y.get());
return r;
}
template <class R1, class R2, class R3, class R4>
quantity<typename boost::ratio_add<R1, R3>::type,
typename boost::ratio_add<R2, R4>::type>
operator*(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
{
typedef quantity<typename boost::ratio_add<R1, R3>::type,
typename boost::ratio_add<R2, R4>::type> R;
R r;
r.set(x.get() * y.get());
return r;
}
template <class R1, class R2>
quantity<R1, R2>
operator+(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
{
typedef quantity<R1, R2> R;
R r;
r.set(x.get() + y.get());
return r;
}
template <class R1, class R2>
quantity<R1, R2>
operator-(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
{
typedef quantity<R1, R2> R;
R r;
r.set(x.get() - y.get());
return r;
}
With all of the foregoing scaffolding, we can now write an exemplar of a type-safe physics function:
Distance
compute_distance(Speed v0, Time t, Acceleration a)
{
return v0 * t + Scalar(.5) * a * t * t; // if a units mistake is made here it won't compile
}
Finally, we can exercise what we've created, even using custom time durations (`User1::seconds`) as well as Boost time durations (`boost::chrono::hours`). The input can be in arbitrary, though type-safe, units, the output is always in SI units. (A complete Units library would support other units, of course.)
int main()
{
typedef boost::__ratio<8, BOOST_INTMAX_C(0x7FFFFFFFD)> R1;
typedef boost::__ratio<3, BOOST_INTMAX_C(0x7FFFFFFFD)> R2;
typedef User1::quantity<boost::ratio_subtract<boost::__ratio<0>, boost::__ratio<1> >::type,
boost::ratio_subtract<boost::__ratio<1>, boost::__ratio<0> >::type > RR;
typedef boost::ratio_subtract<R1, R2>::type RS;
std::cout << RS::num << '/' << RS::den << '\n';
std::cout << "*************\n";
std::cout << "* testUser1 *\n";
std::cout << "*************\n";
User1::Distance d( User1::mile(110) );
User1::Time t( boost::chrono::__hours(2) );
RR r=d / t;
//r.set(d.get() / t.get());
User1::Speed rc= r;
User1::Speed s = d / t;
std::cout << "Speed = " << s.get() << " meters/sec\n";
User1::Acceleration a = User1::Distance( User1::foot(32.2) ) / User1::Time() / User1::Time();
std::cout << "Acceleration = " << a.get() << " meters/sec^2\n";
User1::Distance df = compute_distance(s, User1::Time( User1::seconds(0.5) ), a);
std::cout << "Distance = " << df.get() << " meters\n";
std::cout << "There are "
<< User1::mile::ratio::den << '/' << User1::mile::ratio::num << " miles/meter";
User1::meter mt = 1;
User1::mile mi = mt;
std::cout << " which is approximately " << mi.count() << '\n';
std::cout << "There are "
<< User1::mile::ratio::num << '/' << User1::mile::ratio::den << " meters/mile";
mi = 1;
mt = mi;
std::cout << " which is approximately " << mt.count() << '\n';
User1::attosecond as(1);
User1::seconds sec = as;
std::cout << "1 attosecond is " << sec.count() << " seconds\n";
std::cout << "sec = as; // compiles\n";
sec = User1::seconds(1);
as = sec;
std::cout << "1 second is " << as.count() << " attoseconds\n";
std::cout << "as = sec; // compiles\n";
std::cout << "\n";
return 0;
}
['See the source file [@boost:libs/ratio/example/si_physics.cpp example/si_physics.cpp]]
[endsect]
[endsect]
[/================================]
[section:ext_references External Resources]
[/================================]
[variablelist
[
[[@http://www.open-std.org/jtc1/sc22/wg21 [*C++ Standards Committee's current Working Paper]]]
[The most authoritative reference material for the library is the C++ Standards Committee's current Working Paper (WP). 20.6 Compile-time rational arithmetic "ratio"]
]
[
[[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]]
[From Howard E. Hinnant, Walter E. Brown, Jeff Garland and Marc Paterno. Is very informative and provides motivation for key design decisions]
]
[
[[@http://lwg.github.com/issues/lwg-defects.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]]]
[From Vicente Juan Botet Escriba.]
]
]
[endsect]
[endsect]
[/=================]
[section:reference Reference ]
[/=================]
[/=================================================]
[section:config_hpp Header `<boost/ratio/config.hpp>`]
[/=================================================]
// Configuration macros
#define __BOOST_RATIO_VERSION
#define __BOOST_RATIO_EXTENSIONS
#define __BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0
#define __BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0
#define __BOOST_RATIO_USES_STATIC_ASSERT
#define __BOOST_RATIO_USES_MPL_ASSERT
#define __BOOST_RATIO_USES_ARRAY_ASSERT
[section:ext Extensions]
When __BOOST_RATIO_EXTENSIONS is defined, __Boost_Ratio provides in addition some extension to the C++ standard, see below.
[endsect]
[section:deprecated Deprecated]
When __BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0 is defined the deprecated features stated as DEPRECATED V2 are provided.
When __BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0 is defined the deprecated features stated as DEPRECATED V2 are NOT provided.
[endsect]
[section:version Version]
__BOOST_RATIO_VERSION stands for the Boost.Ratio version which can be 1 or 2. The default up to 1.55 is version 1. Since 1.56 it will be 2.
When __BOOST_RATIO_VERSION is 1 __BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0 is defined by default.
When __BOOST_RATIO_VERSION is 2 __BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0 is defined by default.
[endsect]
[section:assert Static Assert]
When BOOST_NO_CXX11_STATIC_ASSERT is defined, the user can select the way static assertions are reported. Define
* __BOOST_RATIO_USES_STATIC_ASSERT to use Boost.StaticAssert.
* __BOOST_RATIO_USES_MPL_ASSERT to use [*Boost.MPL] static assertions.
* __BOOST_RATIO_USES_ARRAY_ASSERT to use __Boost_Ratio internal static assertions.
The default behavior is as if __BOOST_RATIO_USES_ARRAY_ASSERT was defined.
When __BOOST_RATIO_USES_MPL_ASSERT is not defined the following symbols are defined as shown:
#define BOOST_RATIO_OVERFLOW_IN_ADD "overflow in ratio add"
#define BOOST_RATIO_OVERFLOW_IN_SUB "overflow in ratio sub"
#define BOOST_RATIO_OVERFLOW_IN_MUL "overflow in ratio mul"
#define BOOST_RATIO_OVERFLOW_IN_DIV "overflow in ratio div"
#define BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE "ratio numerator is out of range"
#define BOOST_RATIO_DIVIDE_BY_0 "ratio divide by 0"
#define BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE "ratio denominator is out of range"
Depending upon the static assertion system used, a hint as to the failing assertion will appear in some form in the compiler diagnostic output.
[endsect]
[endsect]
[/=================================================]
[section:std C++0x Recommendation]
[/=================================================]
[/=================================================]
[section:ratio_ratio_hpp Header `<boost/ratio.hpp>`]
[/=================================================]
This header includes all the ratio related header files
#include <boost/ratio/ratio.hpp>
#include <boost/ratio/ratio_io.hpp>
#include <boost/ratio/rational_constant.hpp>
[endsect]
[/========================================================]
[section:ratio_fwdhpp Header `<boost/ratio/ratio_fwd.hpp>`]
[/========================================================]
This header provides forward declarations for the `<boost/ratio/ratio.hpp>` file.
namespace boost {
template <boost::intmax_t N, boost::intmax_t D = 1> class __ratio;
// ratio arithmetic
template <class R1, class R2> struct __ratio_add;
template <class R1, class R2> struct __ratio_subtract;
template <class R1, class R2> struct __ratio_multiply;
template <class R1, class R2> struct __ratio_divide;
#ifdef BOOST_RATIO_EXTENSIONS
template <class R,int P> struct __ratio_power;
template <class R> struct __ratio_negate;
template <class R> struct __ratio_sign;
template <class R> struct __ratio_abs;
template <class R1, class R2> struct __ratio_gcd;
template <class R1, class R2> struct __ratio_lcm;
#endif
// ratio comparison
template <class R1, class R2> struct __ratio_equal;
template <class R1, class R2> struct __ratio_not_equal;
template <class R1, class R2> struct __ratio_less;
template <class R1, class R2> struct __ratio_less_equal;
template <class R1, class R2> struct __ratio_greater;
template <class R1, class R2> struct __ratio_greater_equal;
// convenience SI typedefs
typedef ratio<1LL, 1000000000000000000LL> __atto;
typedef ratio<1LL, 1000000000000000LL> __femto;
typedef ratio<1LL, 1000000000000LL> __pico;
typedef ratio<1LL, 1000000000LL> __nano;
typedef ratio<1LL, 1000000LL> __micro;
typedef ratio<1LL, 1000LL> __milli;
typedef ratio<1LL, 100LL> __centi;
typedef ratio<1LL, 10LL> __deci;
typedef ratio< 10LL, 1LL> __deca;
typedef ratio< 100LL, 1LL> __hecto;
typedef ratio< 1000LL, 1LL> __kilo;
typedef ratio< 1000000LL, 1LL> __mega;
typedef ratio< 1000000000LL, 1LL> __giga;
typedef ratio< 1000000000000LL, 1LL> __tera;
typedef ratio< 1000000000000000LL, 1LL> __peta;
typedef ratio<1000000000000000000LL, 1LL> __exa;
#ifdef BOOST_RATIO_EXTENSIONS
// convenience IEC typedefs
typedef ratio< 1024LL> __kibi;
typedef ratio< 1024LL*1024LL> __mebi;
typedef ratio< 1024LL*1024LL*1024LL> __gibi;
typedef ratio< 1024LL*1024LL*1024LL*1024LL> __tebi;
typedef ratio< 1024LL*1024LL*1024LL*1024LL*1024LL> __pebi;
typedef ratio<1024LL*1024LL*1024LL*1024LL*1024LL*1024LL> __exbi;
#endif
}
[endsect]
[/=================================================]
[section:ratio_hpp Header `<boost/ratio/ratio.hpp>`]
[/=================================================]
__ratio is a facility which is useful in specifying compile-time rational constants. Compile-time rational arithmetic is supported with protection against overflow and divide by zero. Such a facility is very handy to efficiently represent 1/3 of a nanosecond, or to specify an inch in terms of meters (for example 254/10000 meters - which __ratio will reduce to 127/5000 meters).
[section:ratio Class Template `ratio<>`]
template <boost::intmax_t N, boost::intmax_t D>
class ratio {
public:
static const boost::intmax_t num;
static const boost::intmax_t den;
typedef ratio<num, den> type;
#ifdef __BOOST_RATIO_EXTENSIONS
typedef mpl::rational_c_tag tag;
typedef boost::rational<boost::intmax_t> value_type;
typedef boost::intmax_t num_type;
typedef boost::intmax_t den_type;
ratio() = default;
template <intmax_t _N2, intmax_t _D2>
ratio(const ratio<_N2, _D2>&);
template <intmax_t _N2, intmax_t _D2>
ratio& operator=(const ratio<_N2, _D2>&);
static value_type value();
value_type operator()() const;
#endif
};
A diagnostic will be emitted if __ratio is instantiated with `D == 0`, or if the absolute value of `N` or `D` cannot be represented. [*Note:] These rules ensure that infinite ratios are avoided and that for any negative input, there exists a representable value of its absolute value which is positive. In a two's complement representation, this excludes the most negative value.
The members num and den will be normalized values of the template arguments N and D computed as follows. Let `gcd` denote the greatest common divisor of `N`'s absolute value and of `D`'s absolute value. Then:
* `num` has the value `sign(N)*sign(D)*abs(N)/gcd`.
* `den` has the value `abs(D)/gcd`.
The nested typedef `type` denotes the normalized form of this __ratio type. It should be
used when the normalized form of the template arguments are required, since the arguments are not necessarily normalized.
Two __ratio classes `__ratio<N1,D1>` and `__ratio<N2,D2>` have the same normalized form if `__ratio<N1,D1>::type` is the same type as `__ratio<N2,D2>::type`
[section:ca Construction and Assignment]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
[heading Default Constructor]
ratio()=default;
[*Effects:] Constructs a __ratio object.
[heading Copy Constructor]
template <intmax_t N2, intmax_t D2>
ratio(const __ratio<N2, D2>& r);
[*Effects:] Constructs a __ratio object.
[*Remarks:] This constructor will not participate in overload resolution unless `r` has the same normalized form as `*this`.
[heading Assignement]
template <intmax_t N2, intmax_t D2>
__ratio& operator=(const __ratio<N2, D2>& r);
[*Effects:] Assigns a __ratio object.
[*Returns:] *this.
[*Remarks:] This operator will not participate in overload resolution unless `r` has the same normalized form as `*this`.
[endsect]
[section:mpl MPL Numeric Metafunctions]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
In order to work with [*Boost.MPL] numeric metafunctions as a __Rational_Constant, the following has beed added:
typedef mpl::rational_c_tag tag;
typedef boost::rational<boost::intmax_t> value_type;
typedef boost::intmax_t num_type;
typedef boost::intmax_t den_type;
[endsect]
[section:obs Observers]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
static value_type value();
value_type operator()() const;
[*Returns:] value_type(num,den);
[endsect]
[endsect]
[section:ratio_arithmetic `ratio` Arithmetic]
For each of the class templates in this section, each template parameter refers to a `ratio`. If the implementation is unable to form the indicated __ratio due to overflow, a diagnostic will be issued.
[heading `ratio_add<>`]
template <class R1, class R2> struct ratio_add {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<R1::num * R2::den + R2::num * R1::den, R1::den * R2::den>::type`.
[heading `ratio_subtract<>`]
template <class R1, class R2> struct ratio_subtract {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<R1::num * R2::den - R2::num * R1::den, R1::den * R2::den>::type`.
[heading `ratio_multiply<>`]
template <class R1, class R2> struct ratio_multiply {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<R1::num * R2::num, R1::den * R2::den>::type`.
[heading `ratio_divide<>`]
template <class R1, class R2> struct ratio_divide {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<R1::num * R2::den, R2::num * R1::den>::type`.
[heading `ratio_power<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
template <class R, int P> struct ratio_power {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `R* *R` P times.
[heading `ratio_negate<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
template <class R> struct ratio_negate {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<-R::num, R::den>::type`.
[heading `ratio_abs<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
template <class R> struct ratio_abs {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `__ratio<abs_c<intmax_t,R::num>::value, R::den>::type`.
[heading `ratio_sign<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
template <class R> struct ratio_sign {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `sign_c<intmax_t,R::num>::type`.
[heading `ratio_gcd<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
template <class R1, class R2> struct ratio_gcd {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `ratio<gcd_c<intmax_t, R1::num, R2::num>::value, mpl::lcm_c<intmax_t, R1::den, R2::den>::value>::type`.
[heading `ratio_lcm<>`]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
This extension of the C++ standard helps in the definition of some [*Boost.MPL] numeric metafunctions.
template <class R1, class R2> struct ratio_lcm {
typedef [/see below] type;
};
The nested typedef `type` is a synonym for `ratio<lcm_c<intmax_t, R1::num, R2::num>::value, gcd_c<intmax_t, R1::den, R2::den>::value>::type`.
[endsect]
[section:ratio_comparison `ratio` Comparison]
[heading `ratio_equal<>`]
template <class R1, class R2> struct ratio_equal
: public boost::integral_constant<bool, [/see below] > {};
If R1::num == R2::num && R1::den == R2::den, ratio_equal derives from true_type, else derives from false_type.
[heading `ratio_not_equal<>`]
template <class R1, class R2> struct ratio_not_equal
: public boost::integral_constant<bool, !ratio_equal<R1, R2>::value> {};
[heading `ratio_less<>`]
template <class R1, class R2>
struct ratio_less
: public boost::integral_constant<bool, [/see below] > {};
If R1::num * R2::den < R2::num * R1::den, ratio_less derives from true_type, else derives from false_type.
[heading `ratio_less_equal<>`]
template <class R1, class R2> struct ratio_less_equal
: public boost::integral_constant<bool, !ratio_less<R2, R1>::value> {};
[heading `ratio_greater<>`]
template <class R1, class R2> struct ratio_greater
: public boost::integral_constant<bool, ratio_less<R2, R1>::value> {};
[heading `ratio_greater_equal<>`]
template <class R1, class R2> struct ratio_greater_equal
: public boost::integral_constant<bool, !ratio_less<R1, R2>::value> {};
[endsect]
[section:ratio_si_typedefs SI typedefs]
The [@http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes International System of Units] specifies twenty SI prefixes. __Boost_Ratio defines all except `yocto`, `zepto`, `zetta`, and `yotta`
// convenience SI typedefs
typedef __ratio<1LL, 1000000000000000000LL> atto;
typedef __ratio<1LL, 1000000000000000LL> femto;
typedef __ratio<1LL, 1000000000000LL> pico;
typedef __ratio<1LL, 1000000000LL> nano;
typedef __ratio<1LL, 1000000LL> micro;
typedef __ratio<1LL, 1000LL> milli;
typedef __ratio<1LL, 100LL> centi;
typedef __ratio<1LL, 10LL> deci;
typedef __ratio< 10LL, 1LL> deca;
typedef __ratio< 100LL, 1LL> hecto;
typedef __ratio< 1000LL, 1LL> kilo;
typedef __ratio< 1000000LL, 1LL> mega;
typedef __ratio< 1000000000LL, 1LL> giga;
typedef __ratio< 1000000000000LL, 1LL> tera;
typedef __ratio< 1000000000000000LL, 1LL> peta;
typedef __ratio<1000000000000000000LL, 1LL> exa;
[endsect]
[section:ratio_iec_typedefs IEC typedefs]
Included only if __BOOST_RATIO_EXTENSIONS is defined.
The [@http://http://en.wikipedia.org/wiki/Binary_prefix#Specific_units_of_IEC_60027-2_A.2_and_ISO.2FIEC_80000 Specific units of IEC 60027-2 A.2 and ISO/IEC 80000] specifies height IEC prefixes. __Boost_Ratio defines all except `zebi` and `yobi`
// convenience ETC typedefs
typedef ratio< 1024LL> kibi;
typedef ratio< 1024LL*1024LL> mebi;
typedef ratio< 1024LL*1024LL*1024LL> gibi;
typedef ratio< 1024LL*1024LL*1024LL*1024LL> tebi;
typedef ratio< 1024LL*1024LL*1024LL*1024LL*1024LL> pebi;
typedef ratio<1024LL*1024LL*1024LL*1024LL*1024LL*1024LL> exbi;
[endsect]
[section:limitations Limitations]
The following are limitations of Boost.Ratio relative to the specification in the C++0x draft standard:
* Four of the SI units typedefs -- `yocto`, `zepto`, `zetta`, and `yotta` -- are to be conditionally supported, if the range of `intmax_t` allows, but are not supported by __Boost_Ratio.
* Ratio values should be of type static `constexpr intmax_t` (see [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#1122 Ratio values should be constexpr]), but for compiler not supporting `constexpr` today, __Boost_Ratio uses `static const intmax_t` instead.
* Rational arithmetic should use template aliases (see [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3134.html#921 Rational Arithmetic should use template aliases]), but those are not available in C++03, so inheritance is used instead.
[endsect]
[section:extensions Extensions]
When __BOOST_RATIO_EXTENSIONS is defined __Boost_Ratio provides the following extensions:
* Extends the requirements of the C++0x draft standard by making the copy constructor and copy assignment operator have the same normalized form (see [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3133.html#1281 copy constructor and assignment between ratios having the same normalized form]).
* More C++ standard like metafunctions applied to ratio types, like __static_abs or __static_negate.
* An __Boost_Mpl rational constant concept and the associated __Boost_Mpl arithmetic and comparison specializations including __numeric_cast, __plus, __equal_to between others.
[endsect]
[endsect]
[endsect]
[section:io Ratio I/O]
[/=======================================================]
[section:ratio_io_hpp Header `<boost/ratio/ratio_io.hpp>`]
[/=======================================================]
This header provides `ratio_string<>` which can generate a textual representation of a `ratio<>` in the form of a `std::basic_string<>`. These strings can be useful for I/O.
namespace boost {
template <class Ratio, class charT> struct ratio_string;
template <> struct ratio_string<atto, char>;
template <> struct ratio_string<atto, char16_t>;
template <> struct ratio_string<atto, char32_t>;
template <> struct ratio_string<atto, wchar_t>;
template <> struct ratio_string<femto, char>;
template <> struct ratio_string<femto, char16_t>;
template <> struct ratio_string<femto, char32_t>;
template <> struct ratio_string<femto, wchar_t>;
template <> struct ratio_string<pico, char>;
template <> struct ratio_string<pico, char16_t>;
template <> struct ratio_string<pico, char32_t>;
template <> struct ratio_string<pico, wchar_t>;
template <> struct ratio_string<nano, char>;
template <> struct ratio_string<nano, char16_t>;
template <> struct ratio_string<nano, char32_t>;
template <> struct ratio_string<nano, wchar_t>;
template <> struct ratio_string<micro, char>;
template <> struct ratio_string<micro, char16_t>;
template <> struct ratio_string<micro, char32_t>;
template <> struct ratio_string<micro, wchar_t>;
template <> struct ratio_string<milli, char>;
template <> struct ratio_string<milli, char16_t>;
template <> struct ratio_string<milli, char32_t>;
template <> struct ratio_string<milli, wchar_t>;
template <> struct ratio_string<centi, char>;
template <> struct ratio_string<centi, char16_t>;
template <> struct ratio_string<centi, char32_t>;
template <> struct ratio_string<centi, wchar_t>;
template <> struct ratio_string<deci, char>;
template <> struct ratio_string<deci, char16_t>;
template <> struct ratio_string<deci, char32_t>;
template <> struct ratio_string<deci, wchar_t>;
template <> struct ratio_string<deca, char>;
template <> struct ratio_string<deca, char16_t>;
template <> struct ratio_string<deca, char32_t>;
template <> struct ratio_string<deca, wchar_t>;
template <> struct ratio_string<hecto, char>;
template <> struct ratio_string<hecto, char16_t>;
template <> struct ratio_string<hecto, char32_t>;
template <> struct ratio_string<hecto, wchar_t>;
template <> struct ratio_string<kilo, char>;
template <> struct ratio_string<kilo, char16_t>;
template <> struct ratio_string<kilo, char32_t>;
template <> struct ratio_string<kilo, wchar_t>;
template <> struct ratio_string<mega, char>;
template <> struct ratio_string<mega, char16_t>;
template <> struct ratio_string<mega, char32_t>;
template <> struct ratio_string<mega, wchar_t>;
template <> struct ratio_string<giga, char>;
template <> struct ratio_string<giga, char16_t>;
template <> struct ratio_string<giga, char32_t>;
template <> struct ratio_string<giga, wchar_t>;
template <> struct ratio_string<tera, char>;
template <> struct ratio_string<tera, char16_t>;
template <> struct ratio_string<tera, char32_t>;
template <> struct ratio_string<tera, wchar_t>;
template <> struct ratio_string<peta, char>;
template <> struct ratio_string<peta, char16_t>;
template <> struct ratio_string<peta, char32_t>;
template <> struct ratio_string<peta, wchar_t>;
template <> struct ratio_string<exa, char>;
template <> struct ratio_string<exa, char16_t>;
template <> struct ratio_string<exa, char32_t>;
template <> struct ratio_string<exa, wchar_t>;
template <> struct ratio_string<kibi, char>;
template <> struct ratio_string<kibi, char16_t>;
template <> struct ratio_string<kibi, char32_t>;
template <> struct ratio_string<kibi, wchar_t>;
template <> struct ratio_string<mebi, char>;
template <> struct ratio_string<mebi, char16_t>;
template <> struct ratio_string<mebi, char32_t>;
template <> struct ratio_string<mebi, wchar_t>;
template <> struct ratio_string<gibi, char>;
template <> struct ratio_string<gibi, char16_t>;
template <> struct ratio_string<gibi, char32_t>;
template <> struct ratio_string<gibi, wchar_t>;
template <> struct ratio_string<tebi, char>;
template <> struct ratio_string<tebi, char16_t>;
template <> struct ratio_string<tebi, char32_t>;
template <> struct ratio_string<tebi, wchar_t>;
template <> struct ratio_string<pebi, char>;
template <> struct ratio_string<pebi, char16_t>;
template <> struct ratio_string<pebi, char32_t>;
template <> struct ratio_string<pebi, wchar_t>;
template <> struct ratio_string<yobi, char>;
template <> struct ratio_string<yobi, char16_t>;
template <> struct ratio_string<yobi, char32_t>;
template <> struct ratio_string<yobi, wchar_t>;
}
[section:ratio_string Template Class `ratio_string<>`]
template <class Ratio, class CharT>
struct ratio_string
{
static std::basic_string<CharT> symbol();
static std::basic_string<CharT> prefix();
static std::basic_string<CharT> short_name(); // DEPRECATED V2
static std::basic_string<CharT> long_name(); // DEPRECATED V2
};
The class template ratio_string provides textual representations of the associated ratio appropriate for the character type charT.
The primary template provides generic strings. Specializations provide the same static member functions but these functions return the English SI prefix and symbol names as specified by the General Conference on Weights and Measures.
[section:prefix Static Member function `prefix()`]
template<class Ratio, class CharT>
basic_string<charT>
ratio_string<Ratio, CharT>::prefix();
[*Returns]: A basic_string of the form: [Ratio::num/Ratio::den]
[*Example]: `ratio_string<ratio<2, 60>, wchar_t>::prefix()` returns `L"[1/30]"`.
[endsect]
[section:symbol Static Member function `symbol()`]
template<class Ratio, class CharT>
basic_string<charT>
ratio_string<Ratio, CharT>::symbol();
[*Returns]: prefix().
[endsect]
[section:long_name Static Member function `long_name()` DEPRECATED V2]
template<class Ratio, class CharT>
basic_string<charT>
ratio_string<Ratio, CharT>::long_name();
[*Returns]: prefix().
[endsect]
[section:short_name Static Member function `short_name()` DEPRECATED V2]
template<class Ratio, class CharT>
basic_string<charT>
ratio_string<Ratio, CharT>::short_name();
[*Returns]: symbol().
[endsect]
[endsect]
[section:spe Specializations for `ratio_string<>`]
With compilers supporting char16_t and char32_t and with a standard library don't providing std::u16string and std::u32string you will need to
define the macros BOOST_NO_CXX11_U16STRING and BOOST_NO_CXX11_U32STRING until Boost.Config defines them.
For each specialization the table gives the return value for `prefix()` and `symbol()`.
[table The return values of specializations of ratio_string
[[Specialization][`prefix()`] [`symbol()`]]
[[`ratio_string<atto, char>`][`"atto"`] [`"a"`]]
[[`ratio_string<atto, char16_t>`][`u"atto"`] [`u"a"`]]
[[`ratio_string<atto, char32_t>`][`U"atto"`] [`U"a"`]]
[[`ratio_string<atto, wchar_t>`][`L"atto"`] [`L"a"`]]
[[`ratio_string<femto, char>`][`"femto"`] [`"f"`]]
[[`ratio_string<femto, char16_t>`][`u"femto"`] [`u"f"`]]
[[`ratio_string<femto, char32_t>`][`U"femto"`] [`U"f"`]]
[[`ratio_string<femto, wchar_t>`][`L"femto"`] [`L"f"`]]
[[`ratio_string<pico, char>`][`"pico"`] [`"p"`]]
[[`ratio_string<pico, char16_t>`][`u"pico"`] [`u"p"`]]
[[`ratio_string<pico, char32_t>`][`U"pico"`] [`U"p"`]]
[[`ratio_string<pico, wchar_t>`][`L"pico"`] [`L"p"`]]
[[`ratio_string<nano, char>`][`"nano"`] [`"a"`]]
[[`ratio_string<nano, char16_t>`][`u"nano"`] [`u"a"`]]
[[`ratio_string<nano, char32_t>`][`U"nano"`] [`U"a"`]]
[[`ratio_string<nano, wchar_t>`][`L"nano"`] [`L"a"`]]
[[`ratio_string<micro, char>`][`"micro"`] [`u8"\u00B5"`]]
[[`ratio_string<micro, char16_t>`][`u"micro"`] [`u"\u00B5"`]]
[[`ratio_string<micro, char32_t>`][`U"micro"`] [`U"\u00B5"`]]
[[`ratio_string<micro, wchar_t>`][`L"micro"`] [`Lu8"\u00B5"`]]
[[`ratio_string<milli, char>`][`"milli"`] [`"m"`]]
[[`ratio_string<milli, char16_t>`][`u"milli"`] [`u"m"`]]
[[`ratio_string<milli, char32_t>`][`U"milli"`] [`U"m"`]]
[[`ratio_string<milli, wchar_t>`][`L"milli"`] [`L"m"`]]
[[`ratio_string<centi, char>`][`"centi"`] [`"c"`]]
[[`ratio_string<centi, char16_t>`][`u"centi"`] [`u"c"`]]
[[`ratio_string<centi, char32_t>`][`U"centi"`] [`U"c"`]]
[[`ratio_string<centi, wchar_t>`][`L"centi"`] [`L"c"`]]
[[`ratio_string<deci, char>`][`"deci"`] [`"d"`]]
[[`ratio_string<deci, char16_t>`][`u"deci"`] [`u"d"`]]
[[`ratio_string<deci, char32_t>`][`U"deci"`] [`U"d"`]]
[[`ratio_string<deci, wchar_t>`][`L"deci"`] [`L"d"`]]
[[`ratio_string<deca, char>`][`"deca"`] [`"da"`]]
[[`ratio_string<deca, char16_t>`][`u"deca"`] [`u"da"`]]
[[`ratio_string<deca, char32_t>`][`U"deca"`] [`U"da"`]]
[[`ratio_string<deca, wchar_t>`][`L"deca"`] [`L"da"`]]
[[`ratio_string<hecto, char>`][`"hecto"`] [`"h"`]]
[[`ratio_string<hecto, char16_t>`][`u"hecto"`] [`u"h"`]]
[[`ratio_string<hecto, char32_t>`][`U"hecto"`] [`U"h"`]]
[[`ratio_string<hecto, wchar_t>`][`L"hecto"`] [`L"h"`]]
[[`ratio_string<kilo, char>`][`"kilo"`] [`"k"`]]
[[`ratio_string<kilo, char16_t>`][`u"kilo"`] [`u"k"`]]
[[`ratio_string<kilo, char32_t>`][`U"kilo"`] [`U"k"`]]
[[`ratio_string<kilo, wchar_t>`][`L"kilo"`] [`L"k"`]]
[[`ratio_string<mega, char>`][`"mega"`] [`"M"`]]
[[`ratio_string<mega, char16_t>`][`u"mega"`] [`u"M"`]]
[[`ratio_string<mega, char32_t>`][`U"mega"`] [`U"M"`]]
[[`ratio_string<mega, wchar_t>`][`L"mega"`] [`L"M"`]]
[[`ratio_string<giga, char>`][`"giga"`] [`"G"`]]
[[`ratio_string<giga, char16_t>`][`u"giga"`] [`u"G"`]]
[[`ratio_string<giga, char32_t>`][`U"giga"`] [`U"G"`]]
[[`ratio_string<giga, wchar_t>`][`L"giga"`] [`L"G"`]]
[[`ratio_string<tera, char>`][`"tera"`] [`"T"`]]
[[`ratio_string<tera, char16_t>`][`u"tera"`] [`u"T"`]]
[[`ratio_string<tera, char32_t>`][`U"tera"`] [`U"T"`]]
[[`ratio_string<tera, wchar_t>`][`L"tera"`] [`L"T"`]]
[[`ratio_string<peta, char>`][`"peta"`] [`"P"`]]
[[`ratio_string<peta, char16_t>`][`u"peta"`] [`u"P"`]]
[[`ratio_string<peta, char32_t>`][`U"peta"`] [`U"P"`]]
[[`ratio_string<peta, wchar_t>`][`L"peta"`] [`L"P"`]]
[[`ratio_string<exa, char>`][`"exa"`] [`"E"`]]
[[`ratio_string<exa, char16_t>`][`u"exa"`] [`u"E"`]]
[[`ratio_string<exa, char32_t>`][`U"exa"`] [`U"E"`]]
[[`ratio_string<exa, wchar_t>`][`L"exa"`] [`L"E"`]]
]
[endsect]
[endsect]
[endsect]
[section:mpl Rational Constant]
[/===========================================]
[section:rational_constant Rational Constant Concept]
[/===========================================]
[heading Description]
A __Rational_Constant is a holder class for a compile-time value of a rational type. Every __Rational_Constant is also a nullary Metafunction, returning itself. A rational constant object is implicitly convertible to the corresponding run-time value of the rational type.
[heading Expression requirements]
In the following table and subsequent specifications, r is a model of __Rational_Constant.
[table
[[Expression][Type] [Complexity]]
[[`r::tag`][`rational_c_tag`] [Constant time]]
[[`r::value_type`][A rational type] [Constant time]]
[[`r::num_type`][An integral type] [Constant time]]
[[`r::den_type`][An integral type] [Constant time]]
[[`r::num`][An Integral constant expression] [Constant time]]
[[`r::den`][An Integral constant expression] [Constant time]]
[[`r::type`][__Rational_Constant] [Constant time]]
[[`r::value_type const c=r()`][] [Constant time]]
]
[heading Expression semantics]
[table
[[Expression][Semantics]]
[[`r::tag`][r's tag type; r::tag::value is r's conversion rank.]]
[[`r::value_type`][A cv-unqualified type of `r()`]]
[[`r::num_type`][A cv-unqualified type of `r::num`]]
[[`r::den_type`][A cv-unqualified type of `r::den`]]
[[`r::num`][The numerator of the rational constant]]
[[`r::den`][The denominator of the rational constant]]
[[`r::type`][equal_to<n::type,n>::value == true.]]
[[`r::value_type const c=r()`][`r::value_type const c=r::value_type(r::num,r::den)`]]
]
[heading Models]
* __ratio<>
[endsect]
[/===========================================]
[section:rational_constant_hpp Header `<boost/ratio/mpl/rational_constant.hpp>`]
[/===========================================]
This header includes all the rational constant related header files
#include <boost/ratio/mpl/rational_c_tag.hpp>
#include <boost/ratio/mpl/numeric_cast.hpp>
#include <boost/ratio/mpl/arithmetic.hpp>
#include <boost/ratio/mpl/comparison.hpp>
[endsect] [/section:rational_constant_hpp Header `<boost/ratio/rational_constant.hpp>`]
[/===========================================]
[section:mpl_rational_c_tag_hpp Header `<boost/ratio/mpl/rational_c_tag.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
struct rational_c_tag : int_<10> {};
}
}
[endsect] [/section:mpl_rational_c_tag_hpp Header `<boost/ratio/mpl/rational_c_tag.hpp>`]
[/===========================================]
[section:mpl_numeric_cast_hpp Header `<boost/ratio/mpl/numeric_cast.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<> struct numeric_cast< integral_c_tag,rational_c_tag >;
}
}
[section:numeric_cast `mpl::numeric_cast<>` Specialization]
A Integral Constant is seen as a ratio with numerator the Integral Constant value and denominator 1.
template<> struct numeric_cast< integral_c_tag,rational_c_tag >
{
template< typename N > struct apply
: ratio< N::value, 1 >
{
};
};
[endsect] [/section:numeric_cast `mpl::numeric_cast<>` Specialization]
[endsect] [/section:mpl_numeric_cast_hpp Header `<boost/ratio/mpl/numeric_cast.hpp>`]
[/===========================================]
[section:mpl_arithmetic_hpp Header `<boost/ratio/mpl/arithmetic.hpp>`]
[/===========================================]
This header includes all the rational constant arithmetic MPL specializations.
#include <boost/ratio/mpl/plus.hpp>
#include <boost/ratio/mpl/minus.hpp>
#include <boost/ratio/mpl/times.hpp>
#include <boost/ratio/mpl/divides.hpp>
#include <boost/ratio/mpl/negate.hpp>
#include <boost/ratio/mpl/abs.hpp>
#include <boost/ratio/mpl/sign.hpp>
#include <boost/ratio/mpl/gcd.hpp>
#include <boost/ratio/mpl/lcm.hpp>
[endsect] [/section:mpl_arithmetic_hpp Header `<boost/ratio/mpl/arithmetic.hpp>`]
[/===========================================]
[section:mpl_plus_hpp Header `<boost/ratio/mpl/plus.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct plus_impl< rational_c_tag,rational_c_tag >;
}
}
[section:plus_impl `mpl::plus_impl<>` Specialization]
The specialization relays on the __ratio_add template class.
template<>
struct plus_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_add<R1, R2>
{
};
};
[endsect] [/section:plus_impl `mpl::plus_impl<>` Specialization]
[endsect] [/section:mpl_plus_hpp Header `<boost/ratio/mpl/plus.hpp>`]
[/===========================================]
[section:mpl_minus_hpp Header `<boost/ratio/mpl/minus.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct minus_impl< rational_c_tag,rational_c_tag >;
}
}
[section:minus_impl `mpl::minus_impl<>` Specialization]
The specialization relays on the __ratio_subtract template class.
template<>
struct plus_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_subtract<R1, R2>
{
};
};
[endsect] [/section:minus_impl `mpl::minus_impl<>` Specialization]
[endsect] [/section:mpl_minus_hpp Header `<boost/ratio/mpl/minus.hpp>`]
[/===========================================]
[section:mpl_times_hpp Header `<boost/ratio/mpl/times.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct times_impl< rational_c_tag,rational_c_tag >;
}
}
[section:times_impl `mpl::times_impl<>` Specialization]
The specialization relays on the __ratio_multiply template class.
template<>
struct times_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_multiply<R1, R2>
{
};
};
[endsect] [/section:times_impl `mpl::times_impl<>` Specialization]
[endsect] [/section:mpl_times_hpp Header `<boost/ratio/mpl/times.hpp>`]
[/===========================================]
[section:mpl_divides_hpp Header `<boost/ratio/mpl/divides.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct divides_impl< rational_c_tag,rational_c_tag >;
}
}
[section:divides_impl `mpl::divides_impl<>` Specialization]
The specialization relays on the __ratio_divide template class.
template<>
struct divides_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_divide<R1, R2>
{
};
};
[endsect] [/section:divides_impl `mpl::divides_impl<>` Specialization]
[endsect] [/section:mpl_divides_hpp Header `<boost/ratio/mpl/divides.hpp>`]
[/===========================================]
[section:mpl_gcd_hpp Header `<boost/ratio/mpl/gcd.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct gcd_impl< rational_c_tag,rational_c_tag >;
}
}
[section:gcd_impl `mpl::gcd_impl<>` Specialization]
The specialization relays on the __ratio_gcd template class.
template<>
struct gcd_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_gcd<R1, R2>
{
};
};
[endsect] [/section:gcd_impl `mpl::gcd_impl<>` Specialization]
[endsect] [/section:mpl_gcd_hpp Header `<boost/ratio/mpl/gcd.hpp>`]
[/===========================================]
[section:mpl_lcm_hpp Header `<boost/ratio/mpl/lcm.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct lcm_impl< rational_c_tag,rational_c_tag >;
}
}
[section:lcm_impl `mpl::lcm_impl<>` Specialization]
The specialization relays on the __ratio_lcm template class.
template<>
struct lcm_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_lcm<R1, R2>
{
};
};
[endsect] [/section:lcm_impl `mpl::lcm_impl<>` Specialization]
[endsect] [/section:mpl_lcm_hpp Header `<boost/ratio/mpl/lcm.hpp>`]
[/===========================================]
[section:mpl_negate_hpp Header `<boost/ratio/mpl/negate.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct negate_impl< rational_c_tag >;
}
}
[section:negate_impl `mpl::negate_impl<>` Specialization]
The specialization relays on the __ratio_negate template class.
template<>
struct negate_impl< rational_c_tag >
{
template< typename R > struct apply
: __ratio_negate<R>
{
};
};
[endsect] [/section:negate_impl `mpl::negate_impl<>` Specialization]
[endsect] [/section:mpl_negate_hpp Header `<boost/ratio/mpl/negate.hpp>`]
[/===========================================]
[section:mpl_abs_hpp Header `<boost/ratio/mpl/abs.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct abs_impl< rational_c_tag >;
}
}
[section:abs_impl `mpl::abs_impl<>` Specialization]
The specialization relays on the __ratio_abs template class.
template<>
struct abs_impl< rational_c_tag >
{
template< typename R > struct apply
: __ratio_abs<R>
{
};
};
[endsect] [/section:abs_impl `mpl::abs_impl<>` Specialization]
[endsect] [/section:mpl_abs_hpp Header `<boost/ratio/mpl/abs.hpp>`]
[/===========================================]
[section:mpl_sign_hpp Header `<boost/ratio/mpl/sign.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct sign_impl< rational_c_tag >;
}
}
[section:sign_impl `mpl::sign_impl<>` Specialization]
The specialization relays on the __ratio_sign template class.
template<>
struct sign_impl< rational_c_tag >
{
template< typename R > struct apply
: __ratio_sign<R>
{
};
};
[endsect] [/section:sign_impl `mpl::sign_impl<>` Specialization]
[endsect] [/section:mpl_sign_hpp Header `<boost/ratio/mpl/sign.hpp>`]
[/===========================================]
[section:mpl_comparison_hpp Header `<boost/ratio/mpl/comparison.hpp>`]
[/===========================================]
This header includes all the rational constant comparison MPL specializations.
#include <boost/ratio/mpl/equal_to.hpp>
#include <boost/ratio/mpl/not_equal_to.hpp>
#include <boost/ratio/mpl/less.hpp>
#include <boost/ratio/mpl/less_equal.hpp>
#include <boost/ratio/mpl/greater.hpp>
#include <boost/ratio/mpl/greater_equal.hpp>
[endsect] [/section:mpl_comparison_hpp Header `<boost/ratio/mpl/mpl_comparison_hpp.hpp>`]
[/===========================================]
[section:mpl_equal_to_hpp Header `<boost/ratio/mpl/equal_to.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct equal_to_impl< rational_c_tag,rational_c_tag >;
}
}
[section:equal_to `mpl::equal_to_impl<>` Specialization]
The specialization relays on the __ratio_equal template class.
template<>
struct equal_to_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_equal<R1, R2>
{
};
};
[endsect] [/section:equal_to `mpl::equal_to_impl<>` Specialization]
[endsect] [/section:mpl_equal_to_hpp Header `<boost/ratio/mpl/equal_to.hpp>`]
[/===========================================]
[section:mpl_not_equal_to_hpp Header `<boost/ratio/mpl/not_equal_to.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct not_equal_to_impl< rational_c_tag,rational_c_tag >;
}
}
[section:not_equal_to `mpl::not_equal_to_impl<>` Specialization]
The specialization relays on the __ratio_not_equal template class.
template<>
struct not_equal_to_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: __ratio_not_equal<R1, R2>
{
};
};
[endsect] [/section:not_equal_to `mpl::not_equal_to_impl<>` Specialization]
[endsect] [/section:mpl_not_equal_to_hpp Header `<boost/ratio/mpl/not_equal_to.hpp>`]
[/===========================================]
[section:mpl_less_hpp Header `<boost/ratio/mpl/less.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct less_impl< rational_c_tag,rational_c_tag >;
}
}
[section:less `mpl::less_impl<>` Specialization]
The specialization relays on the __ratio_less template class.
template<>
struct less_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: ratio_less<R1, R2>
{
};
};
[endsect] [/section:less `mpl::less_impl<>` Specialization]
[endsect] [/section:mpl_less_hpp Header `<boost/ratio/mpl/less.hpp>`]
[/===========================================]
[section:mpl_less_equal_hpp Header `<boost/ratio/mpl/less_equal.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct less_equal_impl< rational_c_tag,rational_c_tag >;
}
}
[section:less_equal `mpl::less_equal_impl<>` Specialization]
The specialization relays on the __ratio_less_equal template class.
template<>
struct less_equal_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: ratio_less_equal<R1, R2>
{
};
};
[endsect] [/section:less_equal `mpl::less_equal_impl<>` Specialization]
[endsect] [/section:mpl_less_equal_hpp Header `<boost/ratio/mpl/less_equal.hpp>`]
[/===========================================]
[section:mpl_greater_hpp Header `<boost/ratio/mpl/greater.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct greater_impl< rational_c_tag,rational_c_tag >;
}
}
[section:greater `mpl::greater_impl<>` Specialization]
The specialization relays on the __ratio_greater template class.
template<>
struct greater_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: ratio_greater<R1, R2>
{
};
};
[endsect] [/section:greater `mpl::greater_impl<>` Specialization]
[endsect] [/section:mpl_greater_hpp Header `<boost/ratio/mpl/greater.hpp>`]
[/===========================================]
[section:mpl_greater_equal_hpp Header `<boost/ratio/mpl/greater_equal.hpp>`]
[/===========================================]
namespace boost {
namespace mpl {
template<>
struct greater_equal_impl< rational_c_tag,rational_c_tag >;
}
}
[section:greater_equal `mpl::greater_equal_impl<>` Specialization]
The specialization relays on the __ratio_greater_equal template class.
template<>
struct greater_equal_impl< rational_c_tag,rational_c_tag >
{
template< typename R1, typename R2 > struct apply
: ratio_greater_equal<R1, R2>
{
};
};
[endsect] [/section:greater_equal `mpl::greater_equal_impl<>` Specialization]
[endsect] [/section:mpl_greater_equal_hpp Header `<boost/ratio/mpl/greater_equal.hpp>`]
[endsect]
[endsect]
[/=================]
[section Appendices]
[/=================]
[/==================================]
[section:history Appendix A: History]
[/==================================]
[section [*Version 2.1.0, Febreary 1, 2014 - 1.56] ]
[*New Features:]
* [@http://svn.boost.org/trac/boost/ticket/XXXX #XXXX] Add ratio_power.
* [@http://svn.boost.org/trac/boost/ticket/XXXX #XXXX] Add IEC binary prefixes.
[endsect]
[section [*Version 2.0.1, Febreary 1, 2013 - 1.53] ]
[*Fixes:]
* [@http://svn.boost.org/trac/boost/ticket/7616 #7616] br_mul::nan - warning C4293: '<<' : shift count negative or too big, undefined behavior`.
[endsect]
[section [*Version 2.0.0, November 1, 2012 - 1.52] ]
[*Features:]
* Replace the short_name and long_name functions by symbol and prefix functions respectively.
[*Deprecated:]
The ratio_string<>::short_name and ratio_string<>::long_name are deprecated. Use ratio_string<>::symbol and ratio_string<>::prefix respectively. These functions be removed in 1.55.
[*Fixes:]
* [@http://svn.boost.org/trac/boost/ticket/7478 #7478] Compiles fails with compilers supporting char16_t and char32_t fails if the library doesn't provides std::u16string and std::u32string.
[endsect]
[section [*Version 1.0.3, August 1, 2012 - 1.51] ]
[*Fixes:]
* [@http://svn.boost.org/trac/boost/ticket/7075 #7075] Workaround for error: the type of partial specialization template parameter constant "n1" depends on another template parameter.
[endsect]
[section [*Version 1.0.2, April 1, 2012 - 1.50] ]
[*Fixes:]
* [@http://svn.boost.org/trac/boost/ticket/6498 #6498] boost::ratio won't compile with default settings.
[endsect]
[section [*Version 1.0.1, Jan 8, 2011 ] ]
[*Features:]
* Added MPL Rational Constant and the associated numeric metafunction specializations.
[endsect]
[section [*Version 1.0.0, Jan 2, 2011] ]
* Moved ratio to trunk.
* Documentation revision.
[endsect]
[section [*Version 0.2.1, September 27, 2010] ]
[*Fixes:]
* Removal of LLVM adapted files due to incompatible License issue.
[endsect]
[section [*Version 0.2.0, September 22, 2010] ]
[*Features:]
* Added ratio_string traits.
[*Fixes:]
* ratio_less overflow avoided following the algorithm from libc++.
[*Test:]
* A more complete test has been included adapted from the test of from libc++/ratio.
[endsect]
[section [*Version 0.1.0, September 10, 2010] ]
[*Features:]
* Ratio has been extracted from Boost.Chrono.
[endsect]
[endsect] [/section:history Appendix A: History]
[/======================================]
[section:rationale Appendix B: Rationale]
[heading Why ratio needs CopyConstruction and Assignment from ratios having the same normalized form]
Current [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3000.pdf [*N3000]] doesn't allows to copy-construct or assign ratio instances of ratio classes having the same normalized form.
This simple example
__ratio<1,3> r1;
__ratio<3,9> r2;
r1 = r2; // (1)
fails to compile in (1). Other example
__ratio<1,3> r1;
__ratio_subtract<__ratio<2,3>,__ratio<1,3> > r2=r1; // (2)
The type of `__ratio_subtract<__ratio<2,3>,__ratio<1,3> >` could be `__ratio<3,9>` so the compilation could fail in (2). It could also be __ratio<1,3> and the compilation succeeds.
[heading Why ratio needs the nested normalizer typedef type]
The current resolution of issue LWG 1281 acknowledges the need for a nested type typedef, so Boost.Ratio is tracking the likely final version of std::ratio.
[endsect] [/section:rationale Appendix B: Rationale]
[/======================================================]
[section:implementation Appendix C: Implementation Notes]
[heading How does Boost.Ratio try to avoid compile-time rational arithmetic overflow?]
When the result is representable, but a simple application of arithmetic rules would result in overflow, e.g. `ratio_multiply<ratio<INTMAX_MAX,2>,ratio<2,INTMAX_MAX>>` can be reduced to `ratio<1,1>`, but the direct result of `ratio<INTMAX_MAX*2,INTMAX_MAX*2>` would result in overflow.
Boost.Ratio implements some simplifications in order to reduce the possibility of overflow. The general ideas are:
* The `num` and `den` `ratio<>` fields are normalized.
* Use the gcd of some of the possible products that can overflow, and simplify before doing the product.
* Use some equivalences relations that avoid addition or subtraction that can overflow or underflow.
The following subsections cover each case in more detail.
[*ratio_add]
In
(n1/d1)+(n2/d2)=(n1*d2+n2*d1)/(d1*d2)
either n1*d2+n2*d1 or d1*d2 can overflow.
( (n1 * d2) + (n2 * d1) )
--------------------------
(d1 * d2)
Dividing by gcd(d1,d2) on both num and den
( (n1 * (d2/gcd(d1,d2))) + (n2 * (d1/gcd(d1,d2))) )
----------------------------------------------------
((d1 * d2) / gcd(d1,d2))
Multiplying and diving by gcd(n1,n2) in numerator
( ((gcd(n1,n2)*(n1/gcd(n1,n2))) * (d2/gcd(d1,d2))) +
((gcd(n1,n2)*(n2/gcd(n1,n2))) * (d1/gcd(d1,d2)))
)
--------------------------------------------------
( (d1 * d2) / gcd(d1,d2) )
Factorizing gcd(n1,n2)
( gcd(n1,n2) *
( ((n1/gcd(n1,n2)) * (d2/gcd(d1,d2))) + ((n2/gcd(n1,n2)) * (d1/gcd(d1,d2))) )
)
-------------------------------------------------------------------------------
( (d1 * d2) / gcd(d1,d2) )
Regrouping
( gcd(n1,n2) *
( ((n1/gcd(n1,n2)) * (d2/gcd(d1,d2))) + ((n2/gcd(n1,n2)) * (d1/gcd(d1,d2))) )
)
-------------------------------------------------------------------------------
( (d1 / gcd(d1,d2)) * d2 )
Dividing by (d1 / gcd(d1,d2))
( ( gcd(n1,n2) / (d1 / gcd(d1,d2)) ) *
( ((n1/gcd(n1,n2)) * (d2/gcd(d1,d2))) + ((n2/gcd(n1,n2)) * (d1/gcd(d1,d2))) )
)
-------------------------------------------------------------------------------
d2
Dividing by d2
( gcd(n1,n2) / (d1 / gcd(d1,d2)) ) *
( ((n1/gcd(n1,n2)) * (d2/gcd(d1,d2))) + ((n2/gcd(n1,n2)) * (d1/gcd(d1,d2))) / d2 )
This expression correspond to the multiply of two ratios that have less risk of overflow as the initial numerators and denominators appear now in most of the cases divided by a gcd.
For ratio_subtract the reasoning is the same.
[*ratio_multiply]
In
(n1/d1)*(n2/d2)=((n1*n2)/(d1*d2))
either n1*n2 or d1*d2 can overflow.
Dividing by gcc(n1,d2) numerator and denominator
(((n1/gcc(n1,d2))*n2)
---------------------
(d1*(d2/gcc(n1,d2))))
Dividing by gcc(n2,d1)
((n1/gcc(n1,d2))*(n2/gcc(n2,d1)))
---------------------------------
((d1/gcc(n2,d1))*(d2/gcc(n1,d2)))
And now all the initial numerator and denominators have been reduced, avoiding the overflow.
For ratio_divide the reasoning is similar.
[*ratio_less]
In order to evaluate
(n1/d1)<(n2/d2)
without moving to floating-point numbers, two techniques are used:
* First compare the sign of the numerators.
If sign(n1) < sign(n2) the result is true.
If sign(n1) == sign(n2) the result depends on the following after making the numerators positive
* When the sign is equal the technique used is to work with integer division and modulo when the signs are equal.
Let call Qi the integer division of ni and di, and Mi the modulo of ni and di.
ni = Qi * di + Mi and Mi < di
Form
((n1*d2)<(d1*n2))
we get
(((Q1 * d1 + M1)*d2)<(d1*((Q2 * d2 + M2))))
Developing
((Q1 * d1 * d2)+ (M1*d2))<((d1 * Q2 * d2) + (d1*M2))
Dividing by d1*d2
Q1 + (M1/d1) < Q2 + (M2/d2)
If Q1=Q2 the result depends on
(M1/d1) < (M2/d2)
If M1==0==M2 the result is false
If M1=0 M2!=0 the result is true
If M1!=0 M2==0 the result is false
If M1!=0 M2!=0 the result depends on
(d2/M2) < (d1/M1)
If Q1!=Q2, the result of
Q1 + (M1/d1) < Q2 + (M2/d2)
depends only on Q1 and Q2 as Qi are integers and (Mi/di) <1 because Mi<di.
if Q1>Q2, Q1==Q2+k, k>=1
Q2+k + (M1/d1) < Q2 + (M2/d2)
k + (M1/d1) < (M2/d2)
k < (M2/d2) - (M1/d1)
but the difference between two numbers between 0 and 1 can not be greater than 1, so the result is false.
if Q2>Q1, Q2==Q1+k, k>=1
Q1 + (M1/d1) < Q1+k + (M2/d2)
(M1/d1) < k + (M2/d2)
(M1/d1) - (M2/d2) < k
which is always true, so the result is true.
The following table recapitulates this analisys
[table
[[ratio<n1,d1>][ratio<n2,d2>] [Q1] [Q2] [M1] [M2] [Result]]
[[ratio<n1,d1>][ratio<n2,d2>] [Q1] [Q2] [!=0] [!=0] [Q1 < Q2]]
[[ratio<n1,d1>][ratio<n2,d2>] [Q] [Q] [0] [0] [false]]
[[ratio<n1,d1>][ratio<n2,d2>] [Q] [Q] [0] [!=0] [true]]
[[ratio<n1,d1>][ratio<n2,d2>] [Q] [Q] [!=0] [0] [false]]
[[ratio<n1,d1>][ratio<n2,d2>] [Q] [Q] [!=0] [!=0] [ratio_less<ratio<d2,M2>, ratio<d1/M1>>]]
]
[endsect] [/section:implementation Appendix C: Implementation Notes]
[/======================================================]
[section:faq Appendix D: FAQ]
[/======================================================]
[endsect] [/section:faq Appendix D: FAQ]
[/====================================================]
[section:acknowledgements Appendix E: Acknowledgements]
[/====================================================]
The library code was derived from Howard Hinnant's `time2_demo` prototype. Many thanks to Howard for making his code available under the Boost license. The original code was modified by Beman Dawes to conform to Boost conventions.
`time2_demo` contained this comment:
Much thanks to Andrei Alexandrescu, Walter Brown, Peter Dimov, Jeff Garland, Terry Golubiewski, Daniel Krugler, Anthony Williams.
Howard Hinnant, who is the real author of the library, has provided valuable feedback and suggestions during the development of the library. In particular, The ratio_io.hpp source has been adapted from the experimental header `<ratio_io>` from Howard Hinnant.
The acceptance review of Boost.Ratio took place between October 2nd and 11th 2010. Many thanks to Anthony Williams, the review manager, and to all the reviewers: Bruno Santos, Joel Falcou, Robert Stewart, Roland Bock, Tom Tan and Paul A. Bristol.
Thanks to Andrew Chinoff and Paul A. Bristol for his help polishing the documentation.
[endsect] [/section:acknowledgements Appendix E: Acknowledgements]
[/====================================================]
[section:tests Appendix F: Tests]
[/====================================================]
In order to test you need to run
bjam libs/ratio/test
You can also run a specific suite of test by doing
cd libs/chrono/test
bjam ratio
[section `ratio`]
[table
[[Name] [kind] [Description] [Result] [Ticket]]
[[typedefs.pass] [run] [check the num/den are correct for the predefined typedefs] [Pass] [#]]
[[ratio.pass] [run] [check the num/den are correctly simplified] [Pass] [#]]
[[ratio1.fail] [compile-fails] [The template argument D shall not be zero] [Pass] [#]]
[[ratio2.fail] [compile-fails] [the absolute values of the template arguments N and D shall be representable by type intmax_t] [Pass] [#]]
[[ratio3.fail] [compile-fails] [the absolute values of the template arguments N and D shall be representable by type intmax_t] [Pass] [#]]
]
[endsect]
[section `comparison`]
[table
[[Name] [kind] [Description] [Result] [Ticket]]
[[ratio_equal.pass] [run] [check ratio_equal metafunction class] [Pass] [#]]
[[ratio_not_equal.pass] [run] [check ratio_not_equal metafunction class] [Pass] [#]]
[[ratio_less.pass] [run] [check ratio_less metafunction class] [Pass] [#]]
[[ratio_less_equal.pass] [run] [check ratio_less_equal metafunction class] [Pass] [#]]
[[ratio_greater.pass] [run] [check ratio_greater metafunction class] [Pass] [#]]
[[ratio_greater_equal.pass] [run] [check ratio_greater_equal metafunction class] [Pass] [#]]
]
[endsect]
[section `arithmetic`]
[table
[[Name] [kind] [Description] [Result] [Ticket]]
[[ratio_add.pass] [run] [check ratio_add metafunction class] [Pass] [#]]
[[ratio_subtract.pass] [run] [check ratio_subtract metafunction class] [Pass] [#]]
[[ratio_multiply.pass] [run] [check ratio_multiply metafunction class] [Pass] [#]]
[[ratio_divide.pass] [run] [check ratio_divide metafunction class] [Pass] [#]]
[[ratio_add.fail] [compile-fails] [check ratio_add overflow metafunction class] [Pass] [#]]
[[ratio_subtract.fail] [compile-fails] [check ratio_subtract underflow metafunction class] [Pass] [#]]
[[ratio_multiply.fail] [compile-fails] [check ratio_multiply overflow metafunction class] [Pass] [#]]
[[ratio_divide.fail] [compile-fails] [check ratio_divide overflow metafunction class] [Pass] [#]]
]
[endsect]
[endsect] [/section:tests Appendix F: Tests]
[/=====================================]
[section:tickets Appendix G: Tickets]
[/=====================================]
[table
[[Ticket] [Description] [Resolution] [State]]
[[1] [result of metafunctions ratio_multiply and ratio_divide were not normalized ratios.] [Use of the nested ratio typedef type on ratio arithmetic operations.] [Closed]]
[[2] [INTMAX_C is not always defined.] [Replace INTMAX_C by BOOST_INTMAX_C until boost/cstdint.hpp ensures INTMAX_C is always defined.] [Closed]]
[[3] [MSVC reports a warning instead of an error when there is an integral constant overflow.] [manage with MSVC reporting a warning instead of an error when there is an integral constant overflow.] [Closed]]
[[4] [ration_less overflow on cases where it can be avoided.] [Change the algorithm as implemented in libc++.] [Closed]]
[/[#] [XXXX] [XXXX] [Closed]]
]
[endsect] [/section:tickets Appendix G: Tickets]
[/=====================================]
[section:todo Appendix H: Future Plans]
[/=====================================]
[heading For later releases]
* Use template aliases on compiler providing it.
* Implement [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#3135 multiple arguments] ratio arithmetic.
[endsect] [/section:todo Appendix H: Future Plans]
[endsect] [/section Appendices]