Repository: nodejs/node
Pull request: assert: support `Float16Array` in loose deep equality checks

Depends on: https://github.com/nodejs/node/pull/57879

Changed files:
filename: lib/internal/util/comparisons.js
patch: @@ -110,6 +110,7 @@ const {
   isBooleanObject,
   isBigIntObject,
   isSymbolObject,
+  isFloat16Array,
   isFloat32Array,
   isFloat64Array,
   isKeyObject,
@@ -315,7 +316,8 @@ function objectComparisonStart(val1, val2, mode, memos) {
       if (!isPartialArrayBufferView(val1, val2)) {
         return false;
       }
-    } else if (mode === kLoose && (isFloat32Array(val1) || isFloat64Array(val1))) {
+    } else if (mode === kLoose &&
+               (isFloat32Array(val1) || isFloat64Array(val1) || isFloat16Array(val1))) {
       if (!areSimilarFloatArrays(val1, val2)) {
         return false;
       }

filename: test/parallel/test-assert-partial-deep-equal.js
patch: @@ -1,10 +1,15 @@
+// Flags: --js-float16array
+// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
 'use strict';
 
 const common = require('../common');
 const vm = require('node:vm');
 const assert = require('node:assert');
 const { describe, it } = require('node:test');
 
+// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
+const { Float16Array } = globalThis;
+
 const x = ['x'];
 
 function createCircularObject() {
@@ -494,6 +499,11 @@ describe('Object Comparison Tests', () => {
           actual: { dataView: new Uint8Array(3) },
           expected: { dataView: new DataView(new ArrayBuffer(3)) },
         },
+        {
+          description: 'throws when comparing Float16Array([+0.0]) with Float16Array([-0.0])',
+          actual: new Float16Array([+0.0]),
+          expected: new Float16Array([-0.0]),
+        },
         {
           description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
           actual: new Float32Array([+0.0]),

filename: test/parallel/test-assert-typedarray-deepequal.js
patch: @@ -1,9 +1,14 @@
+// Flags: --js-float16array
+// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
 'use strict';
 
 require('../common');
 const assert = require('assert');
 const { test, suite } = require('node:test');
 
+// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
+const { Float16Array } = globalThis;
+
 function makeBlock(f) {
   const args = Array.prototype.slice.call(arguments, 1);
   return function() {
@@ -20,6 +25,7 @@ suite('equalArrayPairs', () => {
     [new Int8Array(1e5), new Int8Array(1e5)],
     [new Int16Array(1e5), new Int16Array(1e5)],
     [new Int32Array(1e5), new Int32Array(1e5)],
+    [new Float16Array(1e5), new Float16Array(1e5)],
     [new Float32Array(1e5), new Float32Array(1e5)],
     [new Float64Array(1e5), new Float64Array(1e5)],
     [new Float32Array([+0.0]), new Float32Array([+0.0])],
@@ -41,6 +47,7 @@ suite('equalArrayPairs', () => {
 
 suite('looseEqualArrayPairs', () => {
   const looseEqualArrayPairs = [
+    [new Float16Array([+0.0]), new Float16Array([-0.0])],
     [new Float32Array([+0.0]), new Float32Array([-0.0])],
     [new Float64Array([+0.0]), new Float64Array([-0.0])],
   ];
@@ -71,6 +78,8 @@ suite('notEqualArrayPairs', () => {
     [new Int16Array([0]), new Uint16Array([256])],
     [new Int16Array([-256]), new Uint16Array([0xff00])], // same bits
     [new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto
+    [new Float16Array([0.1]), new Float16Array([0.0])],
+    [new Float16Array([0.1]), new Float16Array([0.1, 0.2])],
     [new Float32Array([0.1]), new Float32Array([0.0])],
     [new Float32Array([0.1]), new Float32Array([0.1, 0.2])],
     [new Float64Array([0.1]), new Float64Array([0.0])],