11.9Srillig# $NetBSD: cond-cmp-numeric.mk,v 1.9 2025/06/28 22:39:28 rillig Exp $
21.1Srillig#
31.2Srillig# Tests for numeric comparisons in .if conditions.
41.7Srillig#
51.7Srillig# See also:
61.7Srillig#	cond-token-number.mk
71.1Srillig
81.3Srillig.MAKEFLAGS: -dc
91.3Srillig
101.3Srillig# The ${:U...} on the left-hand side is necessary for the parser.
111.3Srillig
121.3Srillig# Even if strtod(3) parses "INF" as +Infinity, make does not accept this
131.3Srillig# since it is not really a number; see TryParseNumber.
141.9Srillig# expect+1: Comparison with ">" requires both operands "INF" and "1e100" to be numeric
151.3Srillig.if !(${:UINF} > 1e100)
161.3Srillig.  error
171.3Srillig.endif
181.3Srillig
191.3Srillig# Neither is NaN a number; see TryParseNumber.
201.9Srillig# expect+1: Comparison with ">" requires both operands "NaN" and "NaN" to be numeric
211.3Srillig.if ${:UNaN} > NaN
221.3Srillig.  error
231.3Srillig.endif
241.3Srillig
251.3Srillig# Since NaN is not parsed as a number, both operands are interpreted
261.3Srillig# as strings and are therefore equal.  If they were parsed as numbers,
271.3Srillig# they would compare unequal, since NaN is unequal to any and everything,
281.3Srillig# including itself.
291.3Srillig.if !(${:UNaN} == NaN)
301.3Srillig.  error
311.3Srillig.endif
321.1Srillig
331.4Srillig# The parsing code in CondParser_Comparison only performs a light check on
341.4Srillig# whether the operator is valid, leaving the rest of the work to the
351.4Srillig# evaluation functions EvalCompareNum and EvalCompareStr.  Ensure that this
361.4Srillig# parse error is properly reported.
371.9Srillig# expect+1: Malformed conditional "123 ! 123"
381.4Srillig.if 123 ! 123
391.4Srillig.  error
401.4Srillig.else
411.4Srillig.  error
421.4Srillig.endif
431.4Srillig
441.5Srillig# Leading spaces are allowed for numbers.
451.5Srillig# See EvalCompare and TryParseNumber.
461.5Srillig.if ${:U 123} < 124
471.5Srillig.else
481.5Srillig.  error
491.5Srillig.endif
501.5Srillig
511.5Srillig# Trailing spaces are NOT allowed for numbers.
521.5Srillig# See EvalCompare and TryParseNumber.
531.9Srillig# expect+1: Comparison with "<" requires both operands "123 " and "124" to be numeric
541.5Srillig.if ${:U123 } < 124
551.5Srillig.  error
561.5Srillig.else
571.5Srillig.  error
581.5Srillig.endif
591.5Srillig
601.1Srilligall:
61