cond-cmp-numeric-eq.mk revision 1.2
11.2Srillig# $NetBSD: cond-cmp-numeric-eq.mk,v 1.2 2020/09/11 15:19:04 rillig Exp $ 21.1Srillig# 31.1Srillig# Tests for numeric comparisons with the == operator in .if conditions. 41.1Srillig 51.1Srillig# This comparison yields the same result, whether numeric or character-based. 61.1Srillig.if 1 == 1 71.1Srillig.else 81.1Srillig.error 91.1Srillig.endif 101.1Srillig 111.1Srillig# This comparison yields the same result, whether numeric or character-based. 121.1Srillig.if 1 == 2 131.1Srillig.error 141.1Srillig.endif 151.1Srillig 161.1Srillig.if 2 == 1 171.1Srillig.error 181.1Srillig.endif 191.1Srillig 201.1Srillig# Scientific notation is supported, as per strtod. 211.1Srillig.if 2e7 == 2000e4 221.1Srillig.else 231.1Srillig.error 241.1Srillig.endif 251.1Srillig 261.1Srillig.if 2000e4 == 2e7 271.1Srillig.else 281.1Srillig.error 291.1Srillig.endif 301.1Srillig 311.1Srillig# Trailing zeroes after the decimal point are irrelevant for the numeric 321.1Srillig# value. 331.1Srillig.if 3.30000 == 3.3 341.1Srillig.else 351.1Srillig.error 361.1Srillig.endif 371.1Srillig 381.1Srillig.if 3.3 == 3.30000 391.1Srillig.else 401.1Srillig.error 411.1Srillig.endif 421.1Srillig 431.1Srillig# As of 2020-08-23, numeric comparison is implemented as parsing both sides 441.1Srillig# as double, and then performing a normal comparison. The range of double is 451.1Srillig# typically 16 or 17 significant digits, therefore these two numbers seem to 461.1Srillig# be equal. 471.1Srillig.if 1.000000000000000001 == 1.000000000000000002 481.1Srillig.else 491.1Srillig.error 501.1Srillig.endif 511.1Srillig 521.2Srillig 531.2Srillig# There is no = operator for numbers. Well, not quite, there is one, but 541.2Srillig# it generates a warning. Therefore it is not used in practice. 551.2Srillig.if !(12345 = 12345) 561.2Srillig. error 571.2Srillig.else 581.2Srillig. error 591.2Srillig.endif 601.2Srillig 611.2Srillig# There is no === operator for numbers either. 621.2Srillig.if !(12345 === 12345) 631.2Srillig. error 641.2Srillig.else 651.2Srillig. error 661.2Srillig.endif 671.2Srillig 681.1Srilligall: 691.1Srillig @:; 70