1*6a7405f5SSimon J. Gerraty# $NetBSD: cond-token-number.mk,v 1.11 2024/08/06 18:00:17 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for number tokens in .if conditions. 4e2eeea75SSimon J. Gerraty# 5e2eeea75SSimon J. Gerraty# TODO: Add introduction. 62c3632d1SSimon J. Gerraty 7956e45f6SSimon J. Gerraty.if 0 8956e45f6SSimon J. Gerraty. error 9956e45f6SSimon J. Gerraty.endif 102c3632d1SSimon J. Gerraty 11956e45f6SSimon J. Gerraty# Even though -0 is a number and would be accepted by strtod, it is not 12956e45f6SSimon J. Gerraty# accepted by the condition parser. 13956e45f6SSimon J. Gerraty# 14956e45f6SSimon J. Gerraty# See the ch_isdigit call in CondParser_String. 15*6a7405f5SSimon J. Gerraty# expect+1: Malformed conditional '-0' 16956e45f6SSimon J. Gerraty.if -0 17956e45f6SSimon J. Gerraty. error 18e2eeea75SSimon J. Gerraty.else 19e2eeea75SSimon J. Gerraty. error 20956e45f6SSimon J. Gerraty.endif 21956e45f6SSimon J. Gerraty 22956e45f6SSimon J. Gerraty# Even though +0 is a number and would be accepted by strtod, it is not 23956e45f6SSimon J. Gerraty# accepted by the condition parser. 24956e45f6SSimon J. Gerraty# 25956e45f6SSimon J. Gerraty# See the ch_isdigit call in CondParser_String. 26*6a7405f5SSimon J. Gerraty# expect+1: Malformed conditional '+0' 27956e45f6SSimon J. Gerraty.if +0 28956e45f6SSimon J. Gerraty. error 29e2eeea75SSimon J. Gerraty.else 30e2eeea75SSimon J. Gerraty. error 31956e45f6SSimon J. Gerraty.endif 32956e45f6SSimon J. Gerraty 33956e45f6SSimon J. Gerraty# Even though -1 is a number and would be accepted by strtod, it is not 34956e45f6SSimon J. Gerraty# accepted by the condition parser. 35956e45f6SSimon J. Gerraty# 36956e45f6SSimon J. Gerraty# See the ch_isdigit call in CondParser_String. 37*6a7405f5SSimon J. Gerraty# expect+1: Malformed conditional '!-1' 38956e45f6SSimon J. Gerraty.if !-1 39956e45f6SSimon J. Gerraty. error 40e2eeea75SSimon J. Gerraty.else 41e2eeea75SSimon J. Gerraty. error 42956e45f6SSimon J. Gerraty.endif 43956e45f6SSimon J. Gerraty 44956e45f6SSimon J. Gerraty# Even though +1 is a number and would be accepted by strtod, it is not 45956e45f6SSimon J. Gerraty# accepted by the condition parser. 46956e45f6SSimon J. Gerraty# 47956e45f6SSimon J. Gerraty# See the ch_isdigit call in CondParser_String. 48*6a7405f5SSimon J. Gerraty# expect+1: Malformed conditional '!+1' 49956e45f6SSimon J. Gerraty.if !+1 50956e45f6SSimon J. Gerraty. error 51e2eeea75SSimon J. Gerraty.else 52e2eeea75SSimon J. Gerraty. error 53956e45f6SSimon J. Gerraty.endif 54956e45f6SSimon J. Gerraty 55d5e0a182SSimon J. Gerraty# When the number comes from an expression though, it may be signed. 56956e45f6SSimon J. Gerraty# XXX: This is inconsistent. 57956e45f6SSimon J. Gerraty.if ${:U+0} 58956e45f6SSimon J. Gerraty. error 59956e45f6SSimon J. Gerraty.endif 60956e45f6SSimon J. Gerraty 61d5e0a182SSimon J. Gerraty# When the number comes from an expression though, it may be signed. 62956e45f6SSimon J. Gerraty# XXX: This is inconsistent. 63956e45f6SSimon J. Gerraty.if !${:U+1} 64956e45f6SSimon J. Gerraty. error 65956e45f6SSimon J. Gerraty.endif 66956e45f6SSimon J. Gerraty 67e2eeea75SSimon J. Gerraty# Hexadecimal numbers are accepted. 68e2eeea75SSimon J. Gerraty.if 0x0 69e2eeea75SSimon J. Gerraty. error 70e2eeea75SSimon J. Gerraty.endif 71e2eeea75SSimon J. Gerraty.if 0x1 72e2eeea75SSimon J. Gerraty.else 73e2eeea75SSimon J. Gerraty. error 74e2eeea75SSimon J. Gerraty.endif 75e2eeea75SSimon J. Gerraty 769f45a3c8SSimon J. Gerraty# This is not a hexadecimal number, even though it has an x. It is 779f45a3c8SSimon J. Gerraty# interpreted as a string instead. In a plain '.if', such a token evaluates 789f45a3c8SSimon J. Gerraty# to true if it is non-empty. In other '.if' directives, such a token is 799f45a3c8SSimon J. Gerraty# evaluated by either FuncDefined or FuncMake. 80e2eeea75SSimon J. Gerraty.if 3x4 81e2eeea75SSimon J. Gerraty.else 82e2eeea75SSimon J. Gerraty. error 83e2eeea75SSimon J. Gerraty.endif 84e2eeea75SSimon J. Gerraty 859f45a3c8SSimon J. Gerraty# Make can do radix conversion from hex. 869f45a3c8SSimon J. GerratyHEX= dead 879f45a3c8SSimon J. Gerraty.if 0x${HEX} == 57005 889f45a3c8SSimon J. Gerraty.else 899f45a3c8SSimon J. Gerraty. error 909f45a3c8SSimon J. Gerraty.endif 919f45a3c8SSimon J. Gerraty 928c973ee2SSimon J. Gerraty# Very small numbers round to 0. 938c973ee2SSimon J. Gerraty.if 12345e-400 948c973ee2SSimon J. Gerraty. error 958c973ee2SSimon J. Gerraty.endif 968c973ee2SSimon J. Gerraty.if 12345e-200 978c973ee2SSimon J. Gerraty.else 988c973ee2SSimon J. Gerraty. error 998c973ee2SSimon J. Gerraty.endif 100956e45f6SSimon J. Gerraty 1018c973ee2SSimon J. Gerraty# Very large numbers round up to infinity on IEEE 754 implementations, or to 1028c973ee2SSimon J. Gerraty# the largest representable number (VAX); in particular, make does not fall 1038c973ee2SSimon J. Gerraty# back to checking whether a variable of that name is defined. 1048c973ee2SSimon J. Gerraty.if 12345e400 1058c973ee2SSimon J. Gerraty.else 1068c973ee2SSimon J. Gerraty. error 1078c973ee2SSimon J. Gerraty.endif 1088c973ee2SSimon J. Gerraty 1098c973ee2SSimon J. Gerratyall: 110