File: ratio.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (67 lines) | stat: -rw-r--r-- 2,998 bytes parent folder | download | duplicates (2)
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
Time resolutions (or em(units of time)) are essential components of time
specifications. Time resolutions are defined by objects of the class
    hi(ratio)tt(std::ratio). 
    
Before the class tt(ratio) can be used, the tthi(ratio) header file must be
included. But the frquently included tt(<chrono>) header file already includes
the tt(ratio) header file.

The class tt(ratio) has two em(template arguments). These are positive
integral numbers surrounded by pointed brackets defining, respectively, the
numerator and denominator of a fraction (by default the denominator equals
1). Examples:
        verb(    ratio<1>        - representing one; 
    ratio<60>       - representing 60
    ratio<1, 1000>  - representing 1/1000.)

The class tt(ratio) defines two directly accessible static data
members: tt(num)hi(ratio: num) represents its numerator, tt(den)hi(ratio: den)
its denominator. A tt(ratio) definition by itself simply defines a certain
amount. E.g., when executing the following program
        verbinsert(//demo examples/ratio.cc)
    1,200 is displayed, as that's the `amount' represented by
tt(ratio<5, 1000>): tt(ratio) simplifies its fraction whenever possible.

Several predefined tt(ratio) types exist. They are, like
tt(ratio) itself, defined in the standard namespace and can be used instead of
the more cumbersome tt(ratio<x>) or tt(ratio<x, y>) specifications:
    tablecenter(8)(llcllcll)(
    rowline()
    row()
    row(cell(tt(yocto))  cell(10+sups(-24)) cellq()
                     cell(tt(zepto))  cell(10+sups(-21)) cellq() cells(2)())
    rowline()
    row()
    row(cell(tt(atto))  cell(10+sups(-18)) cell()
        cell(tt(femto)) cell(10+sups(-15)) cell()
        cell(tt(pico))  cell(10+sups(-12)))
    row(cell(tt(nano))  cell(10+sups(-9)) cell()
        cell(tt(micro)) cell(10+sups(-6)) cell()
        cell(tt(milli)) cell(10+sups(-3)))
    row(cell(tt(centi)) cell(10+sups(-2)) cell()
        cell(tt(deci))  cell(10+sups(-1)))
    rowline()
    row()
    row(cell(tt(deca))  cell(10+sups(1)) cell()
        cell(tt(hecto)) cell(10+sups(2)) cell()
        cell(tt(kilo))  cell(10+sups(3)))
    row(cell(tt(mega))  cell(10+sups(6)) cell()
        cell(tt(giga))  cell(10+sups(9)) cell()
        cell(tt(tera))  cell(10+sups(12)))
    row(cell(tt(peta))  cell(10+sups(15)) cell()
        cell(tt(exa))   cell(10+sups(18)))
    rowline()
    row()
    row(cell(tt(zetta))   cell(10+sups(21)) cell()
        cell(tt(yotta))   cell(10+sups(24)))
    rowline()
    )
 (em(note:) the definitions of the types tt(yocto, zepto, zetta) and tt(yotta)
use integral constants exceeding 64 bits. Although these constants are defined
in bf(C++), they are not available on 64 bit or smaller architectures.)

Time related ratios can very well be interpreted as fractions or multiple of
seconds, with tt(ratio<1, 1>) representing a resolution of one second.

Here is an example showing how these abbreviations can be used:
        verbinsert(-s4 //milli examples/milli.cc)