cond-cmp-numeric.mk revision 1.6
11.6Srillig# $NetBSD: cond-cmp-numeric.mk,v 1.6 2022/09/04 22:55:00 rillig Exp $
21.1Srillig#
31.2Srillig# Tests for numeric comparisons in .if conditions.
41.1Srillig
51.3Srillig.MAKEFLAGS: -dc
61.3Srillig
71.3Srillig# The ${:U...} on the left-hand side is necessary for the parser.
81.3Srillig
91.3Srillig# Even if strtod(3) parses "INF" as +Infinity, make does not accept this
101.3Srillig# since it is not really a number; see TryParseNumber.
111.3Srillig.if !(${:UINF} > 1e100)
121.3Srillig.  error
131.3Srillig.endif
141.3Srillig
151.3Srillig# Neither is NaN a number; see TryParseNumber.
161.3Srillig.if ${:UNaN} > NaN
171.3Srillig.  error
181.3Srillig.endif
191.3Srillig
201.3Srillig# Since NaN is not parsed as a number, both operands are interpreted
211.3Srillig# as strings and are therefore equal.  If they were parsed as numbers,
221.3Srillig# they would compare unequal, since NaN is unequal to any and everything,
231.3Srillig# including itself.
241.3Srillig.if !(${:UNaN} == NaN)
251.3Srillig.  error
261.3Srillig.endif
271.1Srillig
281.4Srillig# The parsing code in CondParser_Comparison only performs a light check on
291.4Srillig# whether the operator is valid, leaving the rest of the work to the
301.4Srillig# evaluation functions EvalCompareNum and EvalCompareStr.  Ensure that this
311.4Srillig# parse error is properly reported.
321.4Srillig#
331.4Srillig# XXX: The warning message does not mention the actual operator.
341.4Srillig.if 123 ! 123
351.4Srillig.  error
361.4Srillig.else
371.4Srillig.  error
381.4Srillig.endif
391.4Srillig
401.5Srillig# Leading spaces are allowed for numbers.
411.5Srillig# See EvalCompare and TryParseNumber.
421.5Srillig.if ${:U 123} < 124
431.5Srillig.else
441.5Srillig.  error
451.5Srillig.endif
461.5Srillig
471.5Srillig# Trailing spaces are NOT allowed for numbers.
481.5Srillig# See EvalCompare and TryParseNumber.
491.6Srillig# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric
501.5Srillig.if ${:U123 } < 124
511.5Srillig.  error
521.5Srillig.else
531.5Srillig.  error
541.5Srillig.endif
551.5Srillig
561.1Srilligall:
571.1Srillig	@:;
58