cond-cmp-numeric-ge.mk revision 1.1
11.1Srillig# $NetBSD: cond-cmp-numeric-ge.mk,v 1.1 2020/08/23 13:50:17 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.1Srillig.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.error
141.1Srillig.endif
151.1Srillig
161.1Srillig.if 2 >= 1
171.1Srillig.else
181.1Srillig.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.error
251.1Srillig.endif
261.1Srillig
271.1Srillig.if 14 >= 5
281.1Srillig.else
291.1Srillig.error
301.1Srillig.endif
311.1Srillig
321.1Srillig# Scientific notation is supported, as per strtod.
331.1Srillig.if 2e7 >= 1e8
341.1Srillig.error
351.1Srillig.endif
361.1Srillig
371.1Srillig.if 1e8 >= 2e7
381.1Srillig.else
391.1Srillig.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.error
461.1Srillig.endif
471.1Srillig
481.1Srillig.if 111.222 >= 3.141
491.1Srillig.else
501.1Srillig.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.error
581.1Srillig.endif
591.1Srillig
601.1Srillig.if 3.7 >= 3.30
611.1Srillig.else
621.1Srillig.error
631.1Srillig.endif
641.1Srillig
651.1Srillig# As of 2020-08-23, numeric comparison is implemented as 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.1Srillig.error
721.1Srillig.endif
731.1Srillig
741.1Srilligall:
751.1Srillig	@:;
76