1*8c973ee2SSimon J. Gerraty# $NetBSD: cond-cmp-numeric.mk,v 1.7 2023/03/04 08:07:29 rillig Exp $ 22c3632d1SSimon J. Gerraty# 32c3632d1SSimon J. Gerraty# Tests for numeric comparisons in .if conditions. 4*8c973ee2SSimon J. Gerraty# 5*8c973ee2SSimon J. Gerraty# See also: 6*8c973ee2SSimon J. Gerraty# cond-token-number.mk 72c3632d1SSimon J. Gerraty 8956e45f6SSimon J. Gerraty.MAKEFLAGS: -dc 9956e45f6SSimon J. Gerraty 10956e45f6SSimon J. Gerraty# The ${:U...} on the left-hand side is necessary for the parser. 11956e45f6SSimon J. Gerraty 12956e45f6SSimon J. Gerraty# Even if strtod(3) parses "INF" as +Infinity, make does not accept this 13956e45f6SSimon J. Gerraty# since it is not really a number; see TryParseNumber. 14*8c973ee2SSimon J. Gerraty# expect+1: Comparison with '>' requires both operands 'INF' and '1e100' to be numeric 15956e45f6SSimon J. Gerraty.if !(${:UINF} > 1e100) 16956e45f6SSimon J. Gerraty. error 17956e45f6SSimon J. Gerraty.endif 18956e45f6SSimon J. Gerraty 19956e45f6SSimon J. Gerraty# Neither is NaN a number; see TryParseNumber. 20*8c973ee2SSimon J. Gerraty# expect+1: Comparison with '>' requires both operands 'NaN' and 'NaN' to be numeric 21956e45f6SSimon J. Gerraty.if ${:UNaN} > NaN 22956e45f6SSimon J. Gerraty. error 23956e45f6SSimon J. Gerraty.endif 24956e45f6SSimon J. Gerraty 25956e45f6SSimon J. Gerraty# Since NaN is not parsed as a number, both operands are interpreted 26956e45f6SSimon J. Gerraty# as strings and are therefore equal. If they were parsed as numbers, 27956e45f6SSimon J. Gerraty# they would compare unequal, since NaN is unequal to any and everything, 28956e45f6SSimon J. Gerraty# including itself. 29956e45f6SSimon J. Gerraty.if !(${:UNaN} == NaN) 30956e45f6SSimon J. Gerraty. error 31956e45f6SSimon J. Gerraty.endif 322c3632d1SSimon J. Gerraty 33e2eeea75SSimon J. Gerraty# The parsing code in CondParser_Comparison only performs a light check on 34e2eeea75SSimon J. Gerraty# whether the operator is valid, leaving the rest of the work to the 35e2eeea75SSimon J. Gerraty# evaluation functions EvalCompareNum and EvalCompareStr. Ensure that this 36e2eeea75SSimon J. Gerraty# parse error is properly reported. 37*8c973ee2SSimon J. Gerraty# expect+1: Malformed conditional (123 ! 123) 38e2eeea75SSimon J. Gerraty.if 123 ! 123 39e2eeea75SSimon J. Gerraty. error 40e2eeea75SSimon J. Gerraty.else 41e2eeea75SSimon J. Gerraty. error 42e2eeea75SSimon J. Gerraty.endif 43e2eeea75SSimon J. Gerraty 4412904384SSimon J. Gerraty# Leading spaces are allowed for numbers. 4512904384SSimon J. Gerraty# See EvalCompare and TryParseNumber. 4612904384SSimon J. Gerraty.if ${:U 123} < 124 4712904384SSimon J. Gerraty.else 4812904384SSimon J. Gerraty. error 4912904384SSimon J. Gerraty.endif 5012904384SSimon J. Gerraty 5112904384SSimon J. Gerraty# Trailing spaces are NOT allowed for numbers. 5212904384SSimon J. Gerraty# See EvalCompare and TryParseNumber. 534fde40d9SSimon J. Gerraty# expect+1: Comparison with '<' requires both operands '123 ' and '124' to be numeric 5412904384SSimon J. Gerraty.if ${:U123 } < 124 5512904384SSimon J. Gerraty. error 5612904384SSimon J. Gerraty.else 5712904384SSimon J. Gerraty. error 5812904384SSimon J. Gerraty.endif 5912904384SSimon J. Gerraty 602c3632d1SSimon J. Gerratyall: 61