[b86468]: / v3 / js / libs / float16.js

Download this file

1252 lines (1235 with data), 42.2 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
/*! @petamoriken/float16 v3.6.5 | MIT License - https://github.com/petamoriken/float16 */
const float16 = (function (exports) {
'use strict';
const THIS_IS_NOT_AN_OBJECT = "This is not an object";
const THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT = "This is not a Float16Array object";
const THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY =
"This constructor is not a subclass of Float16Array";
const THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT =
"The constructor property value is not an object";
const SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT =
"Species constructor didn't return TypedArray object";
const DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH =
"Derived constructor created TypedArray object which was too small length";
const ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER =
"Attempting to access detached ArrayBuffer";
const CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT =
"Cannot convert undefined or null to object";
const CANNOT_CONVERT_A_BIGINT_VALUE_TO_A_NUMBER =
"Cannot convert a BigInt value to a number";
const CANNOT_MIX_BIGINT_AND_OTHER_TYPES =
"Cannot mix BigInt and other types, use explicit conversions";
const ITERATOR_PROPERTY_IS_NOT_CALLABLE = "@@iterator property is not callable";
const REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE =
"Reduce of empty array with no initial value";
const OFFSET_IS_OUT_OF_BOUNDS = "Offset is out of bounds";
function uncurryThis(target) {
return (thisArg, ...args) => {
return ReflectApply(target, thisArg, args);
};
}
function uncurryThisGetter(target, key) {
return uncurryThis(
ReflectGetOwnPropertyDescriptor(
target,
key
).get
);
}
const {
apply: ReflectApply,
construct: ReflectConstruct,
defineProperty: ReflectDefineProperty,
get: ReflectGet,
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
getPrototypeOf: ReflectGetPrototypeOf,
has: ReflectHas,
ownKeys: ReflectOwnKeys,
set: ReflectSet,
setPrototypeOf: ReflectSetPrototypeOf,
} = Reflect;
const NativeProxy = Proxy;
const NativeNumber = Number;
const {
isFinite: NumberIsFinite,
isNaN: NumberIsNaN,
} = NativeNumber;
const {
iterator: SymbolIterator,
species: SymbolSpecies,
toStringTag: SymbolToStringTag,
for: SymbolFor,
} = Symbol;
const NativeObject = Object;
const {
create: ObjectCreate,
defineProperty: ObjectDefineProperty,
freeze: ObjectFreeze,
is: ObjectIs,
} = NativeObject;
const ObjectPrototype = NativeObject.prototype;
const ObjectPrototype__lookupGetter__ = (ObjectPrototype).__lookupGetter__
? uncurryThis( (ObjectPrototype).__lookupGetter__)
: (object, key) => {
if (object == null) {
throw NativeTypeError(
CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT
);
}
let target = NativeObject(object);
do {
const descriptor = ReflectGetOwnPropertyDescriptor(target, key);
if (descriptor !== undefined) {
if (ObjectHasOwn(descriptor, "get")) {
return descriptor.get;
}
return;
}
} while ((target = ReflectGetPrototypeOf(target)) !== null);
};
const ObjectHasOwn = (NativeObject).hasOwn ||
uncurryThis(ObjectPrototype.hasOwnProperty);
const NativeArray = Array;
const ArrayIsArray = NativeArray.isArray;
const ArrayPrototype = NativeArray.prototype;
const ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join);
const ArrayPrototypePush = uncurryThis(ArrayPrototype.push);
const ArrayPrototypeToLocaleString = uncurryThis(
ArrayPrototype.toLocaleString
);
const NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator];
const ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator);
const MathTrunc = Math.trunc;
const NativeArrayBuffer = ArrayBuffer;
const ArrayBufferIsView = NativeArrayBuffer.isView;
const ArrayBufferPrototype = NativeArrayBuffer.prototype;
const ArrayBufferPrototypeSlice = uncurryThis(ArrayBufferPrototype.slice);
const ArrayBufferPrototypeGetByteLength = uncurryThisGetter(ArrayBufferPrototype, "byteLength");
const NativeSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : null;
const SharedArrayBufferPrototypeGetByteLength = NativeSharedArrayBuffer
&& uncurryThisGetter(NativeSharedArrayBuffer.prototype, "byteLength");
const TypedArray = ReflectGetPrototypeOf(Uint8Array);
const TypedArrayFrom = TypedArray.from;
const TypedArrayPrototype = TypedArray.prototype;
const NativeTypedArrayPrototypeSymbolIterator = TypedArrayPrototype[SymbolIterator];
const TypedArrayPrototypeKeys = uncurryThis(TypedArrayPrototype.keys);
const TypedArrayPrototypeValues = uncurryThis(
TypedArrayPrototype.values
);
const TypedArrayPrototypeEntries = uncurryThis(
TypedArrayPrototype.entries
);
const TypedArrayPrototypeSet = uncurryThis(TypedArrayPrototype.set);
const TypedArrayPrototypeReverse = uncurryThis(
TypedArrayPrototype.reverse
);
const TypedArrayPrototypeFill = uncurryThis(TypedArrayPrototype.fill);
const TypedArrayPrototypeCopyWithin = uncurryThis(
TypedArrayPrototype.copyWithin
);
const TypedArrayPrototypeSort = uncurryThis(TypedArrayPrototype.sort);
const TypedArrayPrototypeSlice = uncurryThis(TypedArrayPrototype.slice);
const TypedArrayPrototypeSubarray = uncurryThis(
TypedArrayPrototype.subarray
);
const TypedArrayPrototypeGetBuffer = uncurryThisGetter(
TypedArrayPrototype,
"buffer"
);
const TypedArrayPrototypeGetByteOffset = uncurryThisGetter(
TypedArrayPrototype,
"byteOffset"
);
const TypedArrayPrototypeGetLength = uncurryThisGetter(
TypedArrayPrototype,
"length"
);
const TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter(
TypedArrayPrototype,
SymbolToStringTag
);
const NativeUint16Array = Uint16Array;
const Uint16ArrayFrom = (...args) => {
return ReflectApply(TypedArrayFrom, NativeUint16Array, args);
};
const NativeUint32Array = Uint32Array;
const NativeFloat32Array = Float32Array;
const ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
const ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next);
const GeneratorPrototypeNext = uncurryThis((function* () {})().next);
const IteratorPrototype = ReflectGetPrototypeOf(ArrayIteratorPrototype);
const DataViewPrototype = DataView.prototype;
const DataViewPrototypeGetUint16 = uncurryThis(
DataViewPrototype.getUint16
);
const DataViewPrototypeSetUint16 = uncurryThis(
DataViewPrototype.setUint16
);
const NativeTypeError = TypeError;
const NativeRangeError = RangeError;
const NativeWeakSet = WeakSet;
const WeakSetPrototype = NativeWeakSet.prototype;
const WeakSetPrototypeAdd = uncurryThis(WeakSetPrototype.add);
const WeakSetPrototypeHas = uncurryThis(WeakSetPrototype.has);
const NativeWeakMap = WeakMap;
const WeakMapPrototype = NativeWeakMap.prototype;
const WeakMapPrototypeGet = uncurryThis(WeakMapPrototype.get);
const WeakMapPrototypeHas = uncurryThis(WeakMapPrototype.has);
const WeakMapPrototypeSet = uncurryThis(WeakMapPrototype.set);
const arrayIterators = new NativeWeakMap();
const SafeIteratorPrototype = ObjectCreate(null, {
next: {
value: function next() {
const arrayIterator = WeakMapPrototypeGet(arrayIterators, this);
return ArrayIteratorPrototypeNext(arrayIterator);
},
},
[SymbolIterator]: {
value: function values() {
return this;
},
},
});
function safeIfNeeded(array) {
if (array[SymbolIterator] === NativeArrayPrototypeSymbolIterator) {
return array;
}
const safe = ObjectCreate(SafeIteratorPrototype);
WeakMapPrototypeSet(arrayIterators, safe, ArrayPrototypeSymbolIterator(array));
return safe;
}
const generators = new NativeWeakMap();
const DummyArrayIteratorPrototype = ObjectCreate(IteratorPrototype, {
next: {
value: function next() {
const generator = WeakMapPrototypeGet(generators, this);
return GeneratorPrototypeNext(generator);
},
writable: true,
configurable: true,
},
});
for (const key of ReflectOwnKeys(ArrayIteratorPrototype)) {
if (key === "next") {
continue;
}
ObjectDefineProperty(DummyArrayIteratorPrototype, key, ReflectGetOwnPropertyDescriptor(ArrayIteratorPrototype, key));
}
function wrap(generator) {
const dummy = ObjectCreate(DummyArrayIteratorPrototype);
WeakMapPrototypeSet(generators, dummy, generator);
return dummy;
}
function isObject(value) {
return (value !== null && typeof value === "object") ||
typeof value === "function";
}
function isObjectLike(value) {
return value !== null && typeof value === "object";
}
function isNativeTypedArray(value) {
return TypedArrayPrototypeGetSymbolToStringTag(value) !== undefined;
}
function isNativeBigIntTypedArray(value) {
const typedArrayName = TypedArrayPrototypeGetSymbolToStringTag(value);
return typedArrayName === "BigInt64Array" ||
typedArrayName === "BigUint64Array";
}
function isArrayBuffer(value) {
try {
ArrayBufferPrototypeGetByteLength( (value));
return true;
} catch (e) {
return false;
}
}
function isSharedArrayBuffer(value) {
if (NativeSharedArrayBuffer === null) {
return false;
}
try {
SharedArrayBufferPrototypeGetByteLength( (value));
return true;
} catch (e) {
return false;
}
}
function isOrdinaryArray(value) {
if (!ArrayIsArray(value)) {
return false;
}
if (value[SymbolIterator] === NativeArrayPrototypeSymbolIterator) {
return true;
}
const iterator = value[SymbolIterator]();
return iterator[SymbolToStringTag] === "Array Iterator";
}
function isOrdinaryNativeTypedArray(value) {
if (!isNativeTypedArray(value)) {
return false;
}
if (value[SymbolIterator] === NativeTypedArrayPrototypeSymbolIterator) {
return true;
}
const iterator = value[SymbolIterator]();
return iterator[SymbolToStringTag] === "Array Iterator";
}
function isCanonicalIntegerIndexString(value) {
if (typeof value !== "string") {
return false;
}
const number = NativeNumber(value);
if (value !== number + "") {
return false;
}
if (!NumberIsFinite(number)) {
return false;
}
return number === MathTrunc(number);
}
const brand = SymbolFor("__Float16Array__");
function hasFloat16ArrayBrand(target) {
if (!isObjectLike(target)) {
return false;
}
const prototype = ReflectGetPrototypeOf(target);
if (!isObjectLike(prototype)) {
return false;
}
const constructor = prototype.constructor;
if (constructor === undefined) {
return false;
}
if (!isObject(constructor)) {
throw NativeTypeError(THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
}
return ReflectHas(constructor, brand);
}
const buffer = new NativeArrayBuffer(4);
const floatView = new NativeFloat32Array(buffer);
const uint32View = new NativeUint32Array(buffer);
const baseTable = new NativeUint32Array(512);
const shiftTable = new NativeUint32Array(512);
for (let i = 0; i < 256; ++i) {
const e = i - 127;
if (e < -27) {
baseTable[i] = 0x0000;
baseTable[i | 0x100] = 0x8000;
shiftTable[i] = 24;
shiftTable[i | 0x100] = 24;
} else if (e < -14) {
baseTable[i] = 0x0400 >> (-e - 14);
baseTable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000;
shiftTable[i] = -e - 1;
shiftTable[i | 0x100] = -e - 1;
} else if (e <= 15) {
baseTable[i] = (e + 15) << 10;
baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
shiftTable[i] = 13;
shiftTable[i | 0x100] = 13;
} else if (e < 128) {
baseTable[i] = 0x7c00;
baseTable[i | 0x100] = 0xfc00;
shiftTable[i] = 24;
shiftTable[i | 0x100] = 24;
} else {
baseTable[i] = 0x7c00;
baseTable[i | 0x100] = 0xfc00;
shiftTable[i] = 13;
shiftTable[i | 0x100] = 13;
}
}
function roundToFloat16Bits(num) {
floatView[0] = (num);
const f = uint32View[0];
const e = (f >> 23) & 0x1ff;
return baseTable[e] + ((f & 0x007fffff) >> shiftTable[e]);
}
const mantissaTable = new NativeUint32Array(2048);
const exponentTable = new NativeUint32Array(64);
const offsetTable = new NativeUint32Array(64);
for (let i = 1; i < 1024; ++i) {
let m = i << 13;
let e = 0;
while((m & 0x00800000) === 0) {
m <<= 1;
e -= 0x00800000;
}
m &= ~0x00800000;
e += 0x38800000;
mantissaTable[i] = m | e;
}
for (let i = 1024; i < 2048; ++i) {
mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
}
for (let i = 1; i < 31; ++i) {
exponentTable[i] = i << 23;
}
exponentTable[31] = 0x47800000;
exponentTable[32] = 0x80000000;
for (let i = 33; i < 63; ++i) {
exponentTable[i] = 0x80000000 + ((i - 32) << 23);
}
exponentTable[63] = 0xc7800000;
for (let i = 1; i < 64; ++i) {
if (i !== 32) {
offsetTable[i] = 1024;
}
}
function convertToNumber(float16bits) {
const m = float16bits >> 10;
uint32View[0] = mantissaTable[offsetTable[m] + (float16bits & 0x3ff)] + exponentTable[m];
return floatView[0];
}
const MAX_SAFE_INTEGER = NativeNumber.MAX_SAFE_INTEGER;
function ToIntegerOrInfinity(target) {
if (typeof target === "bigint") {
throw NativeTypeError(CANNOT_CONVERT_A_BIGINT_VALUE_TO_A_NUMBER);
}
const number = NativeNumber(target);
if (NumberIsNaN(number) || number === 0) {
return 0;
}
return MathTrunc(number);
}
function ToLength(target) {
const length = ToIntegerOrInfinity(target);
if (length < 0) {
return 0;
}
return length < MAX_SAFE_INTEGER
? length
: MAX_SAFE_INTEGER;
}
function SpeciesConstructor(target, defaultConstructor) {
if (!isObject(target)) {
throw NativeTypeError(THIS_IS_NOT_AN_OBJECT);
}
const constructor = target.constructor;
if (constructor === undefined) {
return defaultConstructor;
}
if (!isObject(constructor)) {
throw NativeTypeError(THE_CONSTRUCTOR_PROPERTY_VALUE_IS_NOT_AN_OBJECT);
}
const species = constructor[SymbolSpecies];
if (species == null) {
return defaultConstructor;
}
return species;
}
function IsDetachedBuffer(buffer) {
if (isSharedArrayBuffer(buffer)) {
return false;
}
try {
ArrayBufferPrototypeSlice(buffer, 0, 0);
return false;
} catch (e) {}
return true;
}
function defaultCompare(x, y) {
const isXNaN = NumberIsNaN(x);
const isYNaN = NumberIsNaN(y);
if (isXNaN && isYNaN) {
return 0;
}
if (isXNaN) {
return 1;
}
if (isYNaN) {
return -1;
}
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
if (x === 0 && y === 0) {
const isXPlusZero = ObjectIs(x, 0);
const isYPlusZero = ObjectIs(y, 0);
if (!isXPlusZero && isYPlusZero) {
return -1;
}
if (isXPlusZero && !isYPlusZero) {
return 1;
}
}
return 0;
}
const BYTES_PER_ELEMENT = 2;
const float16bitsArrays = new NativeWeakMap();
function isFloat16Array(target) {
return WeakMapPrototypeHas(float16bitsArrays, target) ||
(!ArrayBufferIsView(target) && hasFloat16ArrayBrand(target));
}
function assertFloat16Array(target) {
if (!isFloat16Array(target)) {
throw NativeTypeError(THIS_IS_NOT_A_FLOAT16ARRAY_OBJECT);
}
}
function assertSpeciesTypedArray(target, count) {
const isTargetFloat16Array = isFloat16Array(target);
const isTargetTypedArray = isNativeTypedArray(target);
if (!isTargetFloat16Array && !isTargetTypedArray) {
throw NativeTypeError(SPECIES_CONSTRUCTOR_DIDNT_RETURN_TYPEDARRAY_OBJECT);
}
if (typeof count === "number") {
let length;
if (isTargetFloat16Array) {
const float16bitsArray = getFloat16BitsArray(target);
length = TypedArrayPrototypeGetLength(float16bitsArray);
} else {
length = TypedArrayPrototypeGetLength(target);
}
if (length < count) {
throw NativeTypeError(
DERIVED_CONSTRUCTOR_CREATED_TYPEDARRAY_OBJECT_WHICH_WAS_TOO_SMALL_LENGTH
);
}
}
if (isNativeBigIntTypedArray(target)) {
throw NativeTypeError(CANNOT_MIX_BIGINT_AND_OTHER_TYPES);
}
}
function getFloat16BitsArray(float16) {
const float16bitsArray = WeakMapPrototypeGet(float16bitsArrays, float16);
if (float16bitsArray !== undefined) {
const buffer = TypedArrayPrototypeGetBuffer(float16bitsArray);
if (IsDetachedBuffer(buffer)) {
throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
}
return float16bitsArray;
}
const buffer = (float16).buffer;
if (IsDetachedBuffer(buffer)) {
throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
}
const cloned = ReflectConstruct(Float16Array, [
buffer,
(float16).byteOffset,
(float16).length,
], float16.constructor);
return WeakMapPrototypeGet(float16bitsArrays, cloned);
}
function copyToArray(float16bitsArray) {
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const array = [];
for (let i = 0; i < length; ++i) {
array[i] = convertToNumber(float16bitsArray[i]);
}
return array;
}
const TypedArrayPrototypeGetters = new NativeWeakSet();
for (const key of ReflectOwnKeys(TypedArrayPrototype)) {
if (key === SymbolToStringTag) {
continue;
}
const descriptor = ReflectGetOwnPropertyDescriptor(TypedArrayPrototype, key);
if (ObjectHasOwn(descriptor, "get") && typeof descriptor.get === "function") {
WeakSetPrototypeAdd(TypedArrayPrototypeGetters, descriptor.get);
}
}
const handler = ObjectFreeze( ({
get(target, key, receiver) {
if (isCanonicalIntegerIndexString(key) && ObjectHasOwn(target, key)) {
return convertToNumber(ReflectGet(target, key));
}
if (WeakSetPrototypeHas(TypedArrayPrototypeGetters, ObjectPrototype__lookupGetter__(target, key))) {
return ReflectGet(target, key);
}
return ReflectGet(target, key, receiver);
},
set(target, key, value, receiver) {
if (isCanonicalIntegerIndexString(key) && ObjectHasOwn(target, key)) {
return ReflectSet(target, key, roundToFloat16Bits(value));
}
return ReflectSet(target, key, value, receiver);
},
getOwnPropertyDescriptor(target, key) {
if (isCanonicalIntegerIndexString(key) && ObjectHasOwn(target, key)) {
const descriptor = ReflectGetOwnPropertyDescriptor(target, key);
descriptor.value = convertToNumber(descriptor.value);
return descriptor;
}
return ReflectGetOwnPropertyDescriptor(target, key);
},
defineProperty(target, key, descriptor) {
if (
isCanonicalIntegerIndexString(key) &&
ObjectHasOwn(target, key) &&
ObjectHasOwn(descriptor, "value")
) {
descriptor.value = roundToFloat16Bits(descriptor.value);
return ReflectDefineProperty(target, key, descriptor);
}
return ReflectDefineProperty(target, key, descriptor);
},
}));
class Float16Array {
constructor(input, _byteOffset, _length) {
let float16bitsArray;
if (isFloat16Array(input)) {
float16bitsArray = ReflectConstruct(NativeUint16Array, [getFloat16BitsArray(input)], new.target);
} else if (isObject(input) && !isArrayBuffer(input)) {
let list;
let length;
if (isNativeTypedArray(input)) {
list = input;
length = TypedArrayPrototypeGetLength(input);
const buffer = TypedArrayPrototypeGetBuffer(input);
const BufferConstructor = !isSharedArrayBuffer(buffer)
? (SpeciesConstructor(
buffer,
NativeArrayBuffer
))
: NativeArrayBuffer;
if (IsDetachedBuffer(buffer)) {
throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
}
if (isNativeBigIntTypedArray(input)) {
throw NativeTypeError(CANNOT_MIX_BIGINT_AND_OTHER_TYPES);
}
const data = new BufferConstructor(
length * BYTES_PER_ELEMENT
);
float16bitsArray = ReflectConstruct(NativeUint16Array, [data], new.target);
} else {
const iterator = input[SymbolIterator];
if (iterator != null && typeof iterator !== "function") {
throw NativeTypeError(ITERATOR_PROPERTY_IS_NOT_CALLABLE);
}
if (iterator != null) {
if (isOrdinaryArray(input)) {
list = input;
length = input.length;
} else {
list = [... (input)];
length = list.length;
}
} else {
list = (input);
length = ToLength(list.length);
}
float16bitsArray = ReflectConstruct(NativeUint16Array, [length], new.target);
}
for (let i = 0; i < length; ++i) {
float16bitsArray[i] = roundToFloat16Bits(list[i]);
}
} else {
float16bitsArray = ReflectConstruct(NativeUint16Array, arguments, new.target);
}
const proxy = (new NativeProxy(float16bitsArray, handler));
WeakMapPrototypeSet(float16bitsArrays, proxy, float16bitsArray);
return proxy;
}
static from(src, ...opts) {
const Constructor = this;
if (!ReflectHas(Constructor, brand)) {
throw NativeTypeError(
THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY
);
}
if (Constructor === Float16Array) {
if (isFloat16Array(src) && opts.length === 0) {
const float16bitsArray = getFloat16BitsArray(src);
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
return new Float16Array(
TypedArrayPrototypeGetBuffer(TypedArrayPrototypeSlice(uint16))
);
}
if (opts.length === 0) {
return new Float16Array(
TypedArrayPrototypeGetBuffer(
Uint16ArrayFrom(src, roundToFloat16Bits)
)
);
}
const mapFunc = opts[0];
const thisArg = opts[1];
return new Float16Array(
TypedArrayPrototypeGetBuffer(
Uint16ArrayFrom(src, function (val, ...args) {
return roundToFloat16Bits(
ReflectApply(mapFunc, this, [val, ...safeIfNeeded(args)])
);
}, thisArg)
)
);
}
let list;
let length;
const iterator = src[SymbolIterator];
if (iterator != null && typeof iterator !== "function") {
throw NativeTypeError(ITERATOR_PROPERTY_IS_NOT_CALLABLE);
}
if (iterator != null) {
if (isOrdinaryArray(src)) {
list = src;
length = src.length;
} else if (isOrdinaryNativeTypedArray(src)) {
list = src;
length = TypedArrayPrototypeGetLength(src);
} else {
list = [...src];
length = list.length;
}
} else {
if (src == null) {
throw NativeTypeError(
CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT
);
}
list = NativeObject(src);
length = ToLength(list.length);
}
const array = new Constructor(length);
if (opts.length === 0) {
for (let i = 0; i < length; ++i) {
array[i] = (list[i]);
}
} else {
const mapFunc = opts[0];
const thisArg = opts[1];
for (let i = 0; i < length; ++i) {
array[i] = ReflectApply(mapFunc, thisArg, [list[i], i]);
}
}
return array;
}
static of(...items) {
const Constructor = this;
if (!ReflectHas(Constructor, brand)) {
throw NativeTypeError(
THIS_CONSTRUCTOR_IS_NOT_A_SUBCLASS_OF_FLOAT16ARRAY
);
}
const length = items.length;
if (Constructor === Float16Array) {
const proxy = new Float16Array(length);
const float16bitsArray = getFloat16BitsArray(proxy);
for (let i = 0; i < length; ++i) {
float16bitsArray[i] = roundToFloat16Bits(items[i]);
}
return proxy;
}
const array = new Constructor(length);
for (let i = 0; i < length; ++i) {
array[i] = items[i];
}
return array;
}
keys() {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
return TypedArrayPrototypeKeys(float16bitsArray);
}
values() {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
return wrap((function* () {
for (const val of TypedArrayPrototypeValues(float16bitsArray)) {
yield convertToNumber(val);
}
})());
}
entries() {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
return wrap((function* () {
for (const [i, val] of TypedArrayPrototypeEntries(float16bitsArray)) {
yield ([i, convertToNumber(val)]);
}
})());
}
at(index) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const relativeIndex = ToIntegerOrInfinity(index);
const k = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
if (k < 0 || k >= length) {
return;
}
return convertToNumber(float16bitsArray[k]);
}
map(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
if (Constructor === Float16Array) {
const proxy = new Float16Array(length);
const array = getFloat16BitsArray(proxy);
for (let i = 0; i < length; ++i) {
const val = convertToNumber(float16bitsArray[i]);
array[i] = roundToFloat16Bits(
ReflectApply(callback, thisArg, [val, i, this])
);
}
return proxy;
}
const array = new Constructor(length);
assertSpeciesTypedArray(array, length);
for (let i = 0; i < length; ++i) {
const val = convertToNumber(float16bitsArray[i]);
array[i] = ReflectApply(callback, thisArg, [val, i, this]);
}
return (array);
}
filter(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
const kept = [];
for (let i = 0; i < length; ++i) {
const val = convertToNumber(float16bitsArray[i]);
if (ReflectApply(callback, thisArg, [val, i, this])) {
ArrayPrototypePush(kept, val);
}
}
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const array = new Constructor(kept);
assertSpeciesTypedArray(array);
return (array);
}
reduce(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
if (length === 0 && opts.length === 0) {
throw NativeTypeError(REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE);
}
let accumulator, start;
if (opts.length === 0) {
accumulator = convertToNumber(float16bitsArray[0]);
start = 1;
} else {
accumulator = opts[0];
start = 0;
}
for (let i = start; i < length; ++i) {
accumulator = callback(
accumulator,
convertToNumber(float16bitsArray[i]),
i,
this
);
}
return accumulator;
}
reduceRight(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
if (length === 0 && opts.length === 0) {
throw NativeTypeError(REDUCE_OF_EMPTY_ARRAY_WITH_NO_INITIAL_VALUE);
}
let accumulator, start;
if (opts.length === 0) {
accumulator = convertToNumber(float16bitsArray[length - 1]);
start = length - 2;
} else {
accumulator = opts[0];
start = length - 1;
}
for (let i = start; i >= 0; --i) {
accumulator = callback(
accumulator,
convertToNumber(float16bitsArray[i]),
i,
this
);
}
return accumulator;
}
forEach(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
ReflectApply(callback, thisArg, [
convertToNumber(float16bitsArray[i]),
i,
this,
]);
}
}
find(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
const value = convertToNumber(float16bitsArray[i]);
if (ReflectApply(callback, thisArg, [value, i, this])) {
return value;
}
}
}
findIndex(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
const value = convertToNumber(float16bitsArray[i]);
if (ReflectApply(callback, thisArg, [value, i, this])) {
return i;
}
}
return -1;
}
findLast(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = length - 1; i >= 0; --i) {
const value = convertToNumber(float16bitsArray[i]);
if (ReflectApply(callback, thisArg, [value, i, this])) {
return value;
}
}
}
findLastIndex(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = length - 1; i >= 0; --i) {
const value = convertToNumber(float16bitsArray[i]);
if (ReflectApply(callback, thisArg, [value, i, this])) {
return i;
}
}
return -1;
}
every(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
if (
!ReflectApply(callback, thisArg, [
convertToNumber(float16bitsArray[i]),
i,
this,
])
) {
return false;
}
}
return true;
}
some(callback, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const thisArg = opts[0];
for (let i = 0; i < length; ++i) {
if (
ReflectApply(callback, thisArg, [
convertToNumber(float16bitsArray[i]),
i,
this,
])
) {
return true;
}
}
return false;
}
set(input, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const targetOffset = ToIntegerOrInfinity(opts[0]);
if (targetOffset < 0) {
throw NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS);
}
if (input == null) {
throw NativeTypeError(
CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT
);
}
if (isNativeBigIntTypedArray(input)) {
throw NativeTypeError(
CANNOT_MIX_BIGINT_AND_OTHER_TYPES
);
}
if (isFloat16Array(input)) {
return TypedArrayPrototypeSet(
getFloat16BitsArray(this),
getFloat16BitsArray(input),
targetOffset
);
}
if (isNativeTypedArray(input)) {
const buffer = TypedArrayPrototypeGetBuffer(input);
if (IsDetachedBuffer(buffer)) {
throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
}
}
const targetLength = TypedArrayPrototypeGetLength(float16bitsArray);
const src = NativeObject(input);
const srcLength = ToLength(src.length);
if (targetOffset === Infinity || srcLength + targetOffset > targetLength) {
throw NativeRangeError(OFFSET_IS_OUT_OF_BOUNDS);
}
for (let i = 0; i < srcLength; ++i) {
float16bitsArray[i + targetOffset] = roundToFloat16Bits(src[i]);
}
}
reverse() {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
TypedArrayPrototypeReverse(float16bitsArray);
return this;
}
fill(value, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
TypedArrayPrototypeFill(
float16bitsArray,
roundToFloat16Bits(value),
...safeIfNeeded(opts)
);
return this;
}
copyWithin(target, start, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
TypedArrayPrototypeCopyWithin(float16bitsArray, target, start, ...safeIfNeeded(opts));
return this;
}
sort(compareFn) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const sortCompare = compareFn !== undefined ? compareFn : defaultCompare;
TypedArrayPrototypeSort(float16bitsArray, (x, y) => {
return sortCompare(convertToNumber(x), convertToNumber(y));
});
return this;
}
slice(start, end) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
if (Constructor === Float16Array) {
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
return new Float16Array(
TypedArrayPrototypeGetBuffer(
TypedArrayPrototypeSlice(uint16, start, end)
)
);
}
const length = TypedArrayPrototypeGetLength(float16bitsArray);
const relativeStart = ToIntegerOrInfinity(start);
const relativeEnd = end === undefined ? length : ToIntegerOrInfinity(end);
let k;
if (relativeStart === -Infinity) {
k = 0;
} else if (relativeStart < 0) {
k = length + relativeStart > 0 ? length + relativeStart : 0;
} else {
k = length < relativeStart ? length : relativeStart;
}
let final;
if (relativeEnd === -Infinity) {
final = 0;
} else if (relativeEnd < 0) {
final = length + relativeEnd > 0 ? length + relativeEnd : 0;
} else {
final = length < relativeEnd ? length : relativeEnd;
}
const count = final - k > 0 ? final - k : 0;
const array = new Constructor(count);
assertSpeciesTypedArray(array, count);
if (count === 0) {
return array;
}
const buffer = TypedArrayPrototypeGetBuffer(float16bitsArray);
if (IsDetachedBuffer(buffer)) {
throw NativeTypeError(ATTEMPTING_TO_ACCESS_DETACHED_ARRAYBUFFER);
}
let n = 0;
while (k < final) {
array[n] = convertToNumber(float16bitsArray[k]);
++k;
++n;
}
return (array);
}
subarray(begin, end) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const Constructor = SpeciesConstructor(float16bitsArray, Float16Array);
const uint16 = new NativeUint16Array(
TypedArrayPrototypeGetBuffer(float16bitsArray),
TypedArrayPrototypeGetByteOffset(float16bitsArray),
TypedArrayPrototypeGetLength(float16bitsArray)
);
const uint16Subarray = TypedArrayPrototypeSubarray(uint16, begin, end);
const array = new Constructor(
TypedArrayPrototypeGetBuffer(uint16Subarray),
TypedArrayPrototypeGetByteOffset(uint16Subarray),
TypedArrayPrototypeGetLength(uint16Subarray)
);
assertSpeciesTypedArray(array);
return (array);
}
indexOf(element, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
let from = ToIntegerOrInfinity(opts[0]);
if (from === Infinity) {
return -1;
}
if (from < 0) {
from += length;
if (from < 0) {
from = 0;
}
}
for (let i = from; i < length; ++i) {
if (
ObjectHasOwn(float16bitsArray, i) &&
convertToNumber(float16bitsArray[i]) === element
) {
return i;
}
}
return -1;
}
lastIndexOf(element, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
let from = opts.length >= 1 ? ToIntegerOrInfinity(opts[0]) : length - 1;
if (from === -Infinity) {
return -1;
}
if (from >= 0) {
from = from < length - 1 ? from : length - 1;
} else {
from += length;
}
for (let i = from; i >= 0; --i) {
if (
ObjectHasOwn(float16bitsArray, i) &&
convertToNumber(float16bitsArray[i]) === element
) {
return i;
}
}
return -1;
}
includes(element, ...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const length = TypedArrayPrototypeGetLength(float16bitsArray);
let from = ToIntegerOrInfinity(opts[0]);
if (from === Infinity) {
return false;
}
if (from < 0) {
from += length;
if (from < 0) {
from = 0;
}
}
const isNaN = NumberIsNaN(element);
for (let i = from; i < length; ++i) {
const value = convertToNumber(float16bitsArray[i]);
if (isNaN && NumberIsNaN(value)) {
return true;
}
if (value === element) {
return true;
}
}
return false;
}
join(separator) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);
return ArrayPrototypeJoin(array, separator);
}
toLocaleString(...opts) {
assertFloat16Array(this);
const float16bitsArray = getFloat16BitsArray(this);
const array = copyToArray(float16bitsArray);
return ArrayPrototypeToLocaleString(array, ...safeIfNeeded(opts));
}
get [SymbolToStringTag]() {
if (isFloat16Array(this)) {
return ("Float16Array");
}
}
}
ObjectDefineProperty(Float16Array, "BYTES_PER_ELEMENT", {
value: BYTES_PER_ELEMENT,
});
ObjectDefineProperty(Float16Array, brand, {});
ReflectSetPrototypeOf(Float16Array, TypedArray);
const Float16ArrayPrototype = Float16Array.prototype;
ObjectDefineProperty(Float16ArrayPrototype, "BYTES_PER_ELEMENT", {
value: BYTES_PER_ELEMENT,
});
ObjectDefineProperty(Float16ArrayPrototype, SymbolIterator, {
value: Float16ArrayPrototype.values,
writable: true,
configurable: true,
});
ReflectSetPrototypeOf(Float16ArrayPrototype, TypedArrayPrototype);
function isTypedArray(target) {
return isNativeTypedArray(target) || isFloat16Array(target);
}
function getFloat16(dataView, byteOffset, ...opts) {
return convertToNumber(
DataViewPrototypeGetUint16(dataView, byteOffset, ...safeIfNeeded(opts))
);
}
function setFloat16(dataView, byteOffset, value, ...opts) {
return DataViewPrototypeSetUint16(
dataView,
byteOffset,
roundToFloat16Bits(value),
...safeIfNeeded(opts)
);
}
function hfround(num) {
if (typeof num === "bigint") {
throw NativeTypeError(CANNOT_CONVERT_A_BIGINT_VALUE_TO_A_NUMBER);
}
num = NativeNumber(num);
if (!NumberIsFinite(num) || num === 0) {
return num;
}
const x16 = roundToFloat16Bits(num);
return convertToNumber(x16);
}
exports.Float16Array = Float16Array;
exports.getFloat16 = getFloat16;
exports.hfround = hfround;
exports.isFloat16Array = isFloat16Array;
exports.isTypedArray = isTypedArray;
exports.setFloat16 = setFloat16;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
return exports;
})({});