Skip to content

Commit 7df9558

Browse files
LiviaMedeirosRafaelGSS
authored andcommitted
assert: support Float16Array in loose deep equality checks
PR-URL: #57881 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent b4f6aa8 commit 7df9558

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎lib/internal/util/comparisons.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const {
110110
isBooleanObject,
111111
isBigIntObject,
112112
isSymbolObject,
113+
isFloat16Array,
113114
isFloat32Array,
114115
isFloat64Array,
115116
isKeyObject,
@@ -315,7 +316,8 @@ function objectComparisonStart(val1, val2, mode, memos) {
315316
if(!isPartialArrayBufferView(val1,val2)){
316317
returnfalse;
317318
}
318-
}elseif(mode===kLoose&&(isFloat32Array(val1)||isFloat64Array(val1))){
319+
}elseif(mode===kLoose&&
320+
(isFloat32Array(val1)||isFloat64Array(val1)||isFloat16Array(val1))){
319321
if(!areSimilarFloatArrays(val1,val2)){
320322
returnfalse;
321323
}

‎test/parallel/test-assert-partial-deep-equal.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// Flags: --js-float16array
2+
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
13
'use strict';
24

35
constcommon=require('../common');
46
constvm=require('node:vm');
57
constassert=require('node:assert');
68
const{ describe, it }=require('node:test');
79

10+
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
11+
const{ Float16Array }=globalThis;
12+
813
constx=['x'];
914

1015
functioncreateCircularObject(){
@@ -494,6 +499,11 @@ describe('Object Comparison Tests', () => {
494499
actual: {dataView: newUint8Array(3)},
495500
expected: {dataView: newDataView(newArrayBuffer(3))},
496501
},
502+
{
503+
description: 'throws when comparing Float16Array([+0.0]) with Float16Array([-0.0])',
504+
actual: newFloat16Array([+0.0]),
505+
expected: newFloat16Array([-0.0]),
506+
},
497507
{
498508
description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])',
499509
actual: newFloat32Array([+0.0]),

‎test/parallel/test-assert-typedarray-deepequal.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
// Flags: --js-float16array
2+
// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above
13
'use strict';
24

35
require('../common');
46
constassert=require('assert');
57
const{ test, suite }=require('node:test');
68

9+
// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line
10+
const{ Float16Array }=globalThis;
11+
712
functionmakeBlock(f){
813
constargs=Array.prototype.slice.call(arguments,1);
914
returnfunction(){
@@ -20,6 +25,7 @@ suite('equalArrayPairs', () => {
2025
[newInt8Array(1e5),newInt8Array(1e5)],
2126
[newInt16Array(1e5),newInt16Array(1e5)],
2227
[newInt32Array(1e5),newInt32Array(1e5)],
28+
[newFloat16Array(1e5),newFloat16Array(1e5)],
2329
[newFloat32Array(1e5),newFloat32Array(1e5)],
2430
[newFloat64Array(1e5),newFloat64Array(1e5)],
2531
[newFloat32Array([+0.0]),newFloat32Array([+0.0])],
@@ -41,6 +47,7 @@ suite('equalArrayPairs', () => {
4147

4248
suite('looseEqualArrayPairs',()=>{
4349
constlooseEqualArrayPairs=[
50+
[newFloat16Array([+0.0]),newFloat16Array([-0.0])],
4451
[newFloat32Array([+0.0]),newFloat32Array([-0.0])],
4552
[newFloat64Array([+0.0]),newFloat64Array([-0.0])],
4653
];
@@ -71,6 +78,8 @@ suite('notEqualArrayPairs', () => {
7178
[newInt16Array([0]),newUint16Array([256])],
7279
[newInt16Array([-256]),newUint16Array([0xff00])],// same bits
7380
[newInt32Array([-256]),newUint32Array([0xffffff00])],// ditto
81+
[newFloat16Array([0.1]),newFloat16Array([0.0])],
82+
[newFloat16Array([0.1]),newFloat16Array([0.1,0.2])],
7483
[newFloat32Array([0.1]),newFloat32Array([0.0])],
7584
[newFloat32Array([0.1]),newFloat32Array([0.1,0.2])],
7685
[newFloat64Array([0.1]),newFloat64Array([0.0])],

0 commit comments

Comments
 (0)