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