- Perl 6 Deep Dive
- Andrew Shitov
- 146字
- 2021-07-03 00:05:52
Num versus Numeric versus Real
As you saw in the diagram of the type hierarchy, some of the nodes are placed in ovals instead of rectangle boxes. Those are roles. Roles provide some interfaces to the classes that are inherited from them. We will talk about roles in more detail in Chapter 8, Object-Oriented Programming.
Some of the methods that the Numeric role provides us with are: Real, Int, Rat, Num, and Bool to convert the values to other data types; log, log10, exp, roots, abs, and sqrt for the corresponding mathematical calculations; and the pair prec and succ.
The Real role class gives us, among the rest, the following methods: rand, sign, round, floor, ceiling, and truncate.
If you want to dig deep and see all the connections between the classes, refer to the documentation pages listed at https://docs.perl6.org/type.html.