@@ -619,25 +619,39 @@ $(GNAME EqualExpression):
619
619
620
620
$(P Inequality is defined as the logical negation of equality.)
621
621
622
- $(P If the operands are integral values, the $(USUAL_ARITHMETIC_CONVERSIONS) are applied
622
+ - If the operands are integral values, the $(USUAL_ARITHMETIC_CONVERSIONS) are applied
623
623
to bring them to a common type before comparison. Equality is defined as the bit patterns
624
624
of the common type match exactly.
625
- )
626
625
627
- $(P If the operands are pointers, equality is defined as the bit patterns of the operands
628
- match exactly.
629
- )
626
+ - If the operands are pointers, equality is defined as the bit patterns of the operands
627
+ match exactly. Both types must match, or one can be `typeof(null)`.
630
628
631
- $(P For float, double, and real values, the $(USUAL_ARITHMETIC_CONVERSIONS) are applied
629
+ - For float, double, and real values, the $(USUAL_ARITHMETIC_CONVERSIONS) are applied
632
630
to bring them to a common type before comparison.
633
631
The values $(D -0) and $(D +0) are considered equal.
634
632
If either or both operands are NaN, then $(D ==) returns false and $(D !=) returns $(D true).
635
633
Otherwise, the bit patterns of the common type are compared for equality.
636
- )
637
634
638
- $(P For static and dynamic arrays, equality is defined as the
635
+ - For static and dynamic arrays, equality is defined as the
639
636
lengths of the arrays
640
- matching, and all the elements are equal.
637
+ matching, and the elements in each compare equal.
638
+ The element types must have a common type.
639
+
640
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
641
+ ---
642
+ assert(5 == 5L);
643
+ assert(byte(4) == 4F);
644
+
645
+ int i = 1, j = 1;
646
+ assert(&i != &j);
647
+ assert(&i != null);
648
+
649
+ // elements of different types are comparable, even when different sizes
650
+ int[] ia = ['A', 'B', 'C'];
651
+ assert(ia == "ABC");
652
+ byte[] ba = [1, 2];
653
+ assert(ba == [1F, 2F]);
654
+ ---
641
655
)
642
656
643
657
$(DDOC_DEPRECATED For complex numbers, equality is defined as equivalent to:)
0 commit comments