xref: /freebsd-src/contrib/bmake/unit-tests/cond-cmp-numeric-ne.mk (revision 988758838533b24f5893b36514fe2c68a3f911a2)
1*98875883SSimon J. Gerraty# $NetBSD: cond-cmp-numeric-ne.mk,v 1.3 2023/09/07 05:36:33 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for numeric comparisons with the != operator in .if conditions.
42c3632d1SSimon J. Gerraty
52c3632d1SSimon J. Gerraty# When both sides are equal, the != operator always yields false.
62c3632d1SSimon J. Gerraty.if 1 != 1
72c3632d1SSimon J. Gerraty.  error
82c3632d1SSimon J. Gerraty.endif
92c3632d1SSimon J. Gerraty
102c3632d1SSimon J. Gerraty# This comparison yields the same result, whether numeric or character-based.
112c3632d1SSimon J. Gerraty.if 1 != 2
122c3632d1SSimon J. Gerraty.else
132c3632d1SSimon J. Gerraty.  error
142c3632d1SSimon J. Gerraty.endif
152c3632d1SSimon J. Gerraty
162c3632d1SSimon J. Gerraty.if 2 != 1
172c3632d1SSimon J. Gerraty.else
182c3632d1SSimon J. Gerraty.  error
192c3632d1SSimon J. Gerraty.endif
202c3632d1SSimon J. Gerraty
212c3632d1SSimon J. Gerraty# Scientific notation is supported, as per strtod.
222c3632d1SSimon J. Gerraty.if 2e7 != 2000e4
232c3632d1SSimon J. Gerraty.  error
242c3632d1SSimon J. Gerraty.endif
252c3632d1SSimon J. Gerraty
262c3632d1SSimon J. Gerraty.if 2000e4 != 2e7
272c3632d1SSimon J. Gerraty.  error
282c3632d1SSimon J. Gerraty.endif
292c3632d1SSimon J. Gerraty
302c3632d1SSimon J. Gerraty# Trailing zeroes after the decimal point are irrelevant for the numeric
312c3632d1SSimon J. Gerraty# value.
322c3632d1SSimon J. Gerraty.if 3.30000 != 3.3
332c3632d1SSimon J. Gerraty.  error
342c3632d1SSimon J. Gerraty.endif
352c3632d1SSimon J. Gerraty
362c3632d1SSimon J. Gerraty.if 3.3 != 3.30000
372c3632d1SSimon J. Gerraty.  error
382c3632d1SSimon J. Gerraty.endif
392c3632d1SSimon J. Gerraty
40*98875883SSimon J. Gerraty# Numeric comparison works by parsing both sides
412c3632d1SSimon J. Gerraty# as double, and then performing a normal comparison.  The range of double is
422c3632d1SSimon J. Gerraty# typically 16 or 17 significant digits, therefore these two numbers seem to
432c3632d1SSimon J. Gerraty# be equal.
442c3632d1SSimon J. Gerraty.if 1.000000000000000001 != 1.000000000000000002
452c3632d1SSimon J. Gerraty.  error
462c3632d1SSimon J. Gerraty.endif
472c3632d1SSimon J. Gerraty
482c3632d1SSimon J. Gerratyall:
492c3632d1SSimon J. Gerraty	@:;
50