cond-cmp-numeric-eq.mk revision 1.6
11.6Srillig# $NetBSD: cond-cmp-numeric-eq.mk,v 1.6 2023/06/01 20:56:35 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.4Srillig. 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.4Srillig. error 141.1Srillig.endif 151.1Srillig 161.1Srillig.if 2 == 1 171.4Srillig. error 181.1Srillig.endif 191.1Srillig 201.1Srillig# Scientific notation is supported, as per strtod. 211.1Srillig.if 2e7 == 2000e4 221.1Srillig.else 231.4Srillig. error 241.1Srillig.endif 251.1Srillig 261.1Srillig.if 2000e4 == 2e7 271.1Srillig.else 281.4Srillig. 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.4Srillig. error 361.1Srillig.endif 371.1Srillig 381.1Srillig.if 3.3 == 3.30000 391.1Srillig.else 401.4Srillig. 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.4Srillig. error 501.1Srillig.endif 511.1Srillig 521.5Srillig# Because an IEEE 754 double can only hold integers with a mantissa of 53 531.5Srillig# bits, these two numbers are considered the same. The 993 is rounded down 541.5Srillig# to the 992. 551.5Srillig.if 9007199254740993 == 9007199254740992 561.5Srillig.else 571.5Srillig. error 581.5Srillig.endif 591.5Srillig# The 995 is rounded up, the 997 is rounded down. 601.5Srillig.if 9007199254740995 == 9007199254740997 611.5Srillig.else 621.5Srillig. error Probably a misconfiguration in the floating point environment, \ 631.5Srillig or maybe a machine without IEEE 754 floating point support. 641.5Srillig.endif 651.2Srillig 661.3Srillig# There is no = operator for numbers. 671.6Srillig# expect+1: Malformed conditional (!(12345 = 12345)) 681.2Srillig.if !(12345 = 12345) 691.2Srillig. error 701.2Srillig.else 711.2Srillig. error 721.2Srillig.endif 731.2Srillig 741.2Srillig# There is no === operator for numbers either. 751.6Srillig# expect+1: Malformed conditional (!(12345 === 12345)) 761.2Srillig.if !(12345 === 12345) 771.2Srillig. error 781.2Srillig.else 791.2Srillig. error 801.2Srillig.endif 811.2Srillig 821.1Srilligall: 831.1Srillig @:; 84