Home | History | Annotate | Line # | Download | only in unit-tests
      1 # $NetBSD: cond-cmp-numeric-eq.mk,v 1.9 2025/06/28 22:39:28 rillig Exp $
      2 #
      3 # Tests for numeric comparisons with the == operator in .if conditions.
      4 
      5 # This comparison yields the same result, whether numeric or character-based.
      6 .if 1 == 1
      7 .else
      8 .  error
      9 .endif
     10 
     11 # This comparison yields the same result, whether numeric or character-based.
     12 .if 1 == 2
     13 .  error
     14 .endif
     15 
     16 .if 2 == 1
     17 .  error
     18 .endif
     19 
     20 # Scientific notation is supported, as per strtod.
     21 .if 2e7 == 2000e4
     22 .else
     23 .  error
     24 .endif
     25 
     26 .if 2000e4 == 2e7
     27 .else
     28 .  error
     29 .endif
     30 
     31 # Trailing zeroes after the decimal point are irrelevant for the numeric
     32 # value.
     33 .if 3.30000 == 3.3
     34 .else
     35 .  error
     36 .endif
     37 
     38 .if 3.3 == 3.30000
     39 .else
     40 .  error
     41 .endif
     42 
     43 # Numeric comparison works by parsing both sides
     44 # as double, and then performing a normal comparison.  The range of double is
     45 # typically 16 or 17 significant digits, therefore these two numbers seem to
     46 # be equal.
     47 .if 1.000000000000000001 == 1.000000000000000002
     48 .else
     49 .  error
     50 .endif
     51 
     52 # Because an IEEE 754 double can only hold integers with a mantissa of 53
     53 # bits, these two numbers are considered the same.  The 993 is rounded down
     54 # to the 992.
     55 .if 9007199254740993 == 9007199254740992
     56 .else
     57 . error
     58 .endif
     59 # The 995 is rounded up, the 997 is rounded down.
     60 .if 9007199254740995 == 9007199254740997
     61 .else
     62 . error Probably a misconfiguration in the floating point environment, \
     63 	or maybe a machine without IEEE 754 floating point support.
     64 .endif
     65 
     66 # There is no = operator for numbers.
     67 # expect+1: Malformed conditional "!(12345 = 12345)"
     68 .if !(12345 = 12345)
     69 .  error
     70 .else
     71 .  error
     72 .endif
     73 
     74 # There is no === operator for numbers either.
     75 # expect+1: Malformed conditional "!(12345 === 12345)"
     76 .if !(12345 === 12345)
     77 .  error
     78 .else
     79 .  error
     80 .endif
     81