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