11.3Srillig# $NetBSD: cond-cmp-numeric-gt.mk,v 1.3 2023/09/07 05:36:33 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 false. 61.1Srillig.if 1 > 1 71.2Srillig. error 81.1Srillig.endif 91.1Srillig 101.1Srillig# This comparison yields the same result, whether numeric or character-based. 111.1Srillig.if 1 > 2 121.2Srillig. error 131.1Srillig.endif 141.1Srillig 151.1Srillig.if 2 > 1 161.1Srillig.else 171.2Srillig. error 181.1Srillig.endif 191.1Srillig 201.1Srillig# If this comparison were character-based instead of numerical, the 211.1Srillig# 5 would be > 14 since its first digit is greater. 221.1Srillig.if 5 > 14 231.2Srillig. error 241.1Srillig.endif 251.1Srillig 261.1Srillig.if 14 > 5 271.1Srillig.else 281.2Srillig. error 291.1Srillig.endif 301.1Srillig 311.1Srillig# Scientific notation is supported, as per strtod. 321.1Srillig.if 2e7 > 1e8 331.2Srillig. error 341.1Srillig.endif 351.1Srillig 361.1Srillig.if 1e8 > 2e7 371.1Srillig.else 381.2Srillig. error 391.1Srillig.endif 401.1Srillig 411.1Srillig# Floating pointer numbers can be compared as well. 421.1Srillig# This might be tempting to use for version numbers, but there are a few pitfalls. 431.1Srillig.if 3.141 > 111.222 441.2Srillig. error 451.1Srillig.endif 461.1Srillig 471.1Srillig.if 111.222 > 3.141 481.1Srillig.else 491.2Srillig. error 501.1Srillig.endif 511.1Srillig 521.1Srillig# When parsed as a version number, 3.30 is greater than 3.7. 531.1Srillig# Since make parses numbers as plain numbers, that leads to wrong results. 541.1Srillig# Numeric comparisons are not suited for comparing version number. 551.1Srillig.if 3.30 > 3.7 561.2Srillig. error 571.1Srillig.endif 581.1Srillig 591.1Srillig.if 3.7 > 3.30 601.1Srillig.else 611.2Srillig. error 621.1Srillig.endif 631.1Srillig 641.3Srillig# Numeric comparison works by parsing both sides 651.1Srillig# as double, and then performing a normal comparison. The range of double is 661.1Srillig# typically 16 or 17 significant digits, therefore these two numbers seem to 671.1Srillig# be equal. 681.3Srillig.if 1.000000000000000002 > 1.000000000000000001 691.2Srillig. error 701.1Srillig.endif 711.1Srillig 721.1Srilligall: 731.1Srillig @:; 74