next up previous contents
Next: Units Up: Expressions Previous: Expressions   Contents

Numbers

Numbers can be unsigned 32 bit integers, IPv4 addresses, IPv6 addresses, or floating-point numbers. Arithmetic operators use integer arithmetic unless one of their arguments is a floating-point numbers.

Like Perl, tcng supports not only decimal, hexadecimal, and octal, but also binary integer constants:

123 decimal, 123
0x40 hexadecimal, decimal value 64
0100 octal, decimal value 64
0b101 binary, decimal value 5

IPv4 addresses in dotted quad form (e.g. 216.136.171.196) are also treated as unsigned integers, in host byte order. Similarly, IPv6 addresses in any of the formats described in [RFC2373] are treated as unsigned 128 bit integers.

IPv4 and IPv6 addresses can be used like other integers, except

Also, the / operator works as a mask operator if the left operand is an address, see section 2.7.4.

Examples:

10/3 equals 3
5/2.0 equals 2.5
10.1.2.3 & 0xff000000 equals 10.0.0.0
10.1.2.3/8 equals 10.0.0.0

tcng also supports negative numbers, but they are simply treated as 32 bit unsigned integers that have wrapped around zero, so multiplications and divisions involving negative numbers may return unexpected results.


next up previous contents
Next: Units Up: Expressions Previous: Expressions   Contents
Martin A. Brown 2003-11-06