11.3Srillig# $NetBSD: cond-cmp-numeric-le.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
21.1Srillig#
31.1Srillig# Tests for numeric comparisons with the <= operator in .if conditions.
41.1Srillig
51.1Srillig# When both sides are equal, the <= operator always yields true.
61.1Srillig.if 1 <= 1
71.1Srillig.else
81.2Srillig.  error
91.1Srillig.endif
101.1Srillig
111.1Srillig# This comparison yields the same result, whether numeric or character-based.
121.1Srillig.if 1 <= 2
131.1Srillig.else
141.2Srillig.  error
151.1Srillig.endif
161.1Srillig
171.1Srillig.if 2 <= 1
181.2Srillig.  error
191.1Srillig.endif
201.1Srillig
211.1Srillig# If this comparison were character-based instead of numerical, the
221.1Srillig# 5 would be >= 14 since its first digit is greater.
231.1Srillig.if 5 <= 14
241.1Srillig.else
251.2Srillig.  error
261.1Srillig.endif
271.1Srillig
281.1Srillig.if 14 <= 5
291.2Srillig.  error
301.1Srillig.endif
311.1Srillig
321.1Srillig# Scientific notation is supported, as per strtod.
331.1Srillig.if 2e7 <= 1e8
341.1Srillig.else
351.2Srillig.  error
361.1Srillig.endif
371.1Srillig
381.1Srillig.if 1e8 <= 2e7
391.2Srillig.  error
401.1Srillig.endif
411.1Srillig
421.1Srillig# Floating pointer numbers can be compared as well.
431.1Srillig# This might be tempting to use for version numbers, but there are a few pitfalls.
441.1Srillig.if 3.141 <= 111.222
451.1Srillig.else
461.2Srillig.  error
471.1Srillig.endif
481.1Srillig
491.1Srillig.if 111.222 <= 3.141
501.2Srillig.  error
511.1Srillig.endif
521.1Srillig
531.1Srillig# When parsed as a version number, 3.30 is greater than 3.7.
541.1Srillig# Since make parses numbers as plain numbers, that leads to wrong results.
551.1Srillig# Numeric comparisons are not suited for comparing version number.
561.1Srillig.if 3.30 <= 3.7
571.1Srillig.else
581.2Srillig.  error
591.1Srillig.endif
601.1Srillig
611.1Srillig.if 3.7 <= 3.30
621.2Srillig.  error
631.1Srillig.endif
641.1Srillig
651.3Srillig# Numeric comparison works by parsing both sides
661.1Srillig# as double, and then performing a normal comparison.  The range of double is
671.1Srillig# typically 16 or 17 significant digits, therefore these two numbers seem to
681.1Srillig# be equal.
691.1Srillig.if 1.000000000000000001 <= 1.000000000000000002
701.1Srillig.else
711.2Srillig.  error
721.1Srillig.endif
731.1Srillig
741.1Srilligall:
751.1Srillig	@:;
76