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