xref: /freebsd/contrib/bmake/unit-tests/cond-cmp-numeric-lt.mk (revision 988758838533b24f5893b36514fe2c68a3f911a2)
1# $NetBSD: cond-cmp-numeric-lt.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
2#
3# Tests for numeric comparisons with the < operator in .if conditions.
4
5# When both sides are equal, the < operator always yields false.
6.if 1 < 1
7.  error
8.endif
9
10# This comparison yields the same result, whether numeric or character-based.
11.if 1 < 2
12.else
13.  error
14.endif
15
16.if 2 < 1
17.  error
18.endif
19
20# If this comparison were character-based instead of numerical, the
21# 5 would be > 14 since its first digit is greater.
22.if 5 < 14
23.else
24.  error
25.endif
26
27.if 14 < 5
28.  error
29.endif
30
31# Scientific notation is supported, as per strtod.
32.if 2e7 < 1e8
33.else
34.  error
35.endif
36
37.if 1e8 < 2e7
38.  error
39.endif
40
41# Floating pointer numbers can be compared as well.
42# This might be tempting to use for version numbers, but there are a few pitfalls.
43.if 3.141 < 111.222
44.else
45.  error
46.endif
47
48.if 111.222 < 3.141
49.  error
50.endif
51
52# When parsed as a version number, 3.30 is greater than 3.7.
53# Since make parses numbers as plain numbers, that leads to wrong results.
54# Numeric comparisons are not suited for comparing version number.
55.if 3.30 < 3.7
56.else
57.  error
58.endif
59
60.if 3.7 < 3.30
61.  error
62.endif
63
64# Numeric comparison works by parsing both sides
65# as double, and then performing a normal comparison.  The range of double is
66# typically 16 or 17 significant digits, therefore these two numbers seem to
67# be equal.
68.if 1.000000000000000001 < 1.000000000000000002
69.  error
70.endif
71
72all:
73	@:;
74