[BUG]: `number/float16/base/to-word` mis-rounds subnormals at the 11-bit shift boundary
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, node.js
- Área
- backend
Línea de trabajo
The issue identifies lib/main.js and the subnormal rounding branch as the starting point. Check the conversion against native Float16Array around the 11-bit shift boundary, including positive and negative values and the exact halfway value. Done means the reported mismatches are fixed and focused regression coverage confirms the expected half-precision words; pull request #16511 is already open.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
@stdlib/number/float16/base/to-word returns zero for float32 values just above 2^-25 that should round to the smallest positive half-precision subnormal. Native Float16Array rounds these to 0x0001.
var toWord = require( '@stdlib/number/float16/base/to-word' );
toWord( 2.98038125038147e-8 ); // returns 0x0000, expected 0x0001
toWord( -2.98038125038147e-8 ); // returns 0x8000, expected 0x8001
Comparing against new Float16Array over 20,000 values in [2^-25, 2^-24) shows 10,015 mismatches; the values that should round to 0x0001 are returned as zero. The exact halfway value 2^-25 correctly ties to zero in both implementations.
Root Cause
In lib/main.js, the subnormal rounding path branches on:
if ( shift < 11 ) {
When shift === 11, the code falls into the else branch, which extracts the round bit from the original 23-bit mantissa at the wrong position. With shift = 11 the 11-bit mantissa is shifted out entirely, and the round bit is its lowest bit (bit 10), which the first branch already handles correctly. Values requiring shift > 11 return zero earlier via the f16Exponent < -10 check, so the else branch is only reachable for shift === 11.
Changing the condition to shift <= 11 fixes all mismatches in a 50,000-value sweep.
Environment
- Version:
develop(7cf56423a) - Node.js with native
Float16Arraysupport - The bug is platform-independent and affects the JavaScript path only; the C path returns the bits of an already-encoded
stdlib_float16_t.
Checklist
- Read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- Lenguaje dominante
- JavaScript
- Estrellas
- 6k
- Forks
- 1.3k
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 224
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de stdlib-js/stdlib
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
stdlib-js/stdlib#16655 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Fix JavaScript lint errorsPosiblemente ocupada @protestershankar la tomó hace 5 días. AbiertoGood First Issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
stdlib-js/stdlib#16563 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Fix C lint errorsPosiblemente ocupada @raus7n la tomó hace 14 días. AbiertoGood First Issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
stdlib-js/stdlib#16454 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Fix JavaScript lint errorsPosiblemente ocupada @Devansh-18155 la tomó hace 39 días. AbiertoGood First Issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
stdlib-js/stdlib#15970 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Fix JavaScript lint errorsPosiblemente ocupada @lb1192176991-lab la tomó hace 44 días. AbiertoGood First Issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
stdlib-js/stdlib#15831 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de stdlib-js/stdlib
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 69/100
Los mantenedores suelen responder en 1 día
-
automation chore ci-cd consistency developer-experience difficulty: easy discoverability documentation enhancement github-actions good first issue help wanted hygiene priority: P3 seo shell yaml
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
swc-project/swc-next-issues#394 ·
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
githubnext/gh-aw-workshop#5790 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
adobe/helix-tools-website#480 ·
Los mantenedores suelen responder en 1 día