cond-token-number.mk revision 1.8 1 1.8 rillig # $NetBSD: cond-token-number.mk,v 1.8 2023/03/04 08:07:29 rillig Exp $
2 1.1 rillig #
3 1.2 rillig # Tests for number tokens in .if conditions.
4 1.5 rillig #
5 1.5 rillig # TODO: Add introduction.
6 1.1 rillig
7 1.3 rillig .if 0
8 1.3 rillig . error
9 1.3 rillig .endif
10 1.1 rillig
11 1.3 rillig # Even though -0 is a number and would be accepted by strtod, it is not
12 1.3 rillig # accepted by the condition parser.
13 1.3 rillig #
14 1.3 rillig # See the ch_isdigit call in CondParser_String.
15 1.3 rillig .if -0
16 1.3 rillig . error
17 1.5 rillig .else
18 1.5 rillig . error
19 1.3 rillig .endif
20 1.3 rillig
21 1.3 rillig # Even though +0 is a number and would be accepted by strtod, it is not
22 1.3 rillig # accepted by the condition parser.
23 1.3 rillig #
24 1.3 rillig # See the ch_isdigit call in CondParser_String.
25 1.3 rillig .if +0
26 1.3 rillig . error
27 1.5 rillig .else
28 1.5 rillig . error
29 1.3 rillig .endif
30 1.3 rillig
31 1.3 rillig # Even though -1 is a number and would be accepted by strtod, it is not
32 1.3 rillig # accepted by the condition parser.
33 1.3 rillig #
34 1.3 rillig # See the ch_isdigit call in CondParser_String.
35 1.3 rillig .if !-1
36 1.3 rillig . error
37 1.5 rillig .else
38 1.5 rillig . error
39 1.3 rillig .endif
40 1.3 rillig
41 1.3 rillig # Even though +1 is a number and would be accepted by strtod, it is not
42 1.3 rillig # accepted by the condition parser.
43 1.3 rillig #
44 1.3 rillig # See the ch_isdigit call in CondParser_String.
45 1.3 rillig .if !+1
46 1.3 rillig . error
47 1.5 rillig .else
48 1.5 rillig . error
49 1.3 rillig .endif
50 1.3 rillig
51 1.3 rillig # When the number comes from a variable expression though, it may be signed.
52 1.3 rillig # XXX: This is inconsistent.
53 1.3 rillig .if ${:U+0}
54 1.3 rillig . error
55 1.3 rillig .endif
56 1.3 rillig
57 1.3 rillig # When the number comes from a variable expression though, it may be signed.
58 1.3 rillig # XXX: This is inconsistent.
59 1.3 rillig .if !${:U+1}
60 1.3 rillig . error
61 1.3 rillig .endif
62 1.3 rillig
63 1.4 rillig # Hexadecimal numbers are accepted.
64 1.4 rillig .if 0x0
65 1.4 rillig . error
66 1.4 rillig .endif
67 1.4 rillig .if 0x1
68 1.4 rillig .else
69 1.4 rillig . error
70 1.4 rillig .endif
71 1.4 rillig
72 1.6 rillig # This is not a hexadecimal number, even though it has an x. It is
73 1.6 rillig # interpreted as a string instead. In a plain '.if', such a token evaluates
74 1.6 rillig # to true if it is non-empty. In other '.if' directives, such a token is
75 1.6 rillig # evaluated by either FuncDefined or FuncMake.
76 1.4 rillig .if 3x4
77 1.4 rillig .else
78 1.4 rillig . error
79 1.4 rillig .endif
80 1.4 rillig
81 1.7 rillig # Make can do radix conversion from hex.
82 1.6 rillig HEX= dead
83 1.6 rillig .if 0x${HEX} == 57005
84 1.6 rillig .else
85 1.6 rillig . error
86 1.6 rillig .endif
87 1.6 rillig
88 1.8 rillig # Very small numbers round to 0.
89 1.8 rillig .if 12345e-400
90 1.8 rillig . error
91 1.8 rillig .endif
92 1.8 rillig .if 12345e-200
93 1.8 rillig .else
94 1.8 rillig . error
95 1.8 rillig .endif
96 1.8 rillig
97 1.8 rillig # Very large numbers round up to infinity on IEEE 754 implementations, or to
98 1.8 rillig # the largest representable number (VAX); in particular, make does not fall
99 1.8 rillig # back to checking whether a variable of that name is defined.
100 1.8 rillig .if 12345e400
101 1.8 rillig .else
102 1.8 rillig . error
103 1.8 rillig .endif
104 1.3 rillig
105 1.8 rillig all:
106