tc39 / test262

Official ECMAScript Conformance Test Suite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tests for Float16Array

bakkot opened this issue Β· comments

The Float16Array proposal is now stage 3 (πŸŽ‰). That means it's time for tests! Here's the things which occur to me offhand; feel free to edit this issue to add more.

  • the usual tests around property descriptors etc
  • rounding behavior (for Float16Array instances as well as for the DataView methods and for f16round), including at least the following cases:
    • 0, NaN, Infinity
    • the largest finite double which is precisely representable as a float16: 65504
    • the smallest integral double which is not precisely representable as a float16: 2049
    • the smallest double which is precisely representable as a non-subnormal float16: 0.00006103515625
    • the largest double which is precisely representable as a subnormal float16: 0.000060975551605224609375
    • the smallest double which is precisely representable precisely as a float16: 0.000000059604644775390625
    • the largest double which rounds to 0 when cast to float16: 0.0000000298023223876953125
    • the smallest double which does not round to 0 when cast to float16, i.e. the next double after the one in the previous bullet point: 0.00000002980232238769531911744490042422139897126953655970282852649688720703125
    • the smallest double which rounds to Infinity when cast to float16: $b^{emax} \times \lparen b - \frac{1}{2} b ^ {1 - p} \rparen$ i.e. $2^{15} \times \lparen 2 - \frac{1}{2} 2 ^ {1 - 11} \rparen =$ 65520
    • the largest double which does not round to Infinity when cast to float16 (i.e. the next double below 65520): 65519.9999999999927240423858165740966796875
    • the smallest double which rounds to a non-subnormal float16: 0.0000610053539276123046875
    • the largest double which rounds to a subnormal float16, i.e. the next double below the one in the previous bullet point: 0.0000610053539276122979112364219655972874534199945628643035888671875
    • some values which are precisely halfway between two adjacent float16 values, to test roundTiesToEven, including
      • a subnormal which rounds up
      • a subnormal which rounds down
      • a number with magnitude between 1 and 2047 which rounds up
      • a number with magnitude between 1 and 2047 which rounds down
      • a number with magnitude above 2047 which rounds up
      • a number with magnitude above 2047 which rounds down
    • all of those again but negative

Incidentally float.exposed is a great tool for exploring the representation of these values, though it has some edge-case bugs when converting between representations (edit: no longer true; I reported the issue and the owner fixed it).

I've started working on this.