xref: /freebsd/contrib/bmake/unit-tests/cond-cmp-numeric-gt.mk (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1# $NetBSD: cond-cmp-numeric-gt.mk,v 1.2 2020/10/24 08:46:08 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.  error
13.endif
14
15.if 2 > 1
16.else
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.  error
24.endif
25
26.if 14 > 5
27.else
28.  error
29.endif
30
31# Scientific notation is supported, as per strtod.
32.if 2e7 > 1e8
33.  error
34.endif
35
36.if 1e8 > 2e7
37.else
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.  error
45.endif
46
47.if 111.222 > 3.141
48.else
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.  error
57.endif
58
59.if 3.7 > 3.30
60.else
61.  error
62.endif
63
64# As of 2020-08-23, numeric comparison is implemented as 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