Unit conversion can turn nonzero values into zero, result in divide-by-zero errors
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- backend
Línea de trabajo
Start with the comparison in src/util/units.ts at the linked lines, then find the tests for unit conversion and Divide, TruncatedDivide, and Modulo. Run the relevant tests and add coverage for the negative and positive examples in the issue. Done means the negative divisor produces the stated result without breaking the positive case or related operations.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
There is an issue with the unit conversion process that turns small negative values into zero, which turns the overall expression into a divide-by-zero error / null.
For instance:
define "DivBySmallNegative": 1 'm' div -0.00000001 'cm'
this currently throws, but the correct result should be -10000000000 '1'. The issue is specifically with negative numbers, since this returns the expected positive value correctly:
define "DivBySmallPositive": 1 'm' div 0.00000001 'cm' // 10000000000 '1'
The sequence that causes the issue:
-
Normalization first tries converting the divisor to m.
-0.00000001 cm → -0.0000000001 m -
Unit conversion rounds that value to zero.
convertUnit calls normalized(), which limits the decimal scale to eight places:-0.0000000001 → 0.00000000
-
This new value is returned based on a comparison that doesn't work correctly for negative values:
https://github.com/cqframework/cql-execution/blob/e8096c64ae8da45fe9a358bbf711bc36d749b696/src/util/units.ts#L132-L134
newVal2.greaterThanOrEquals(val2)Here that becomes:
0 >= -0.00000001 → true
Consequently, it keeps meters and returns these normalized operands:
dividend: 1 m
divisor: 0 m
Note: I think that comparison newVal2.greaterThanOrEquals(val2) can also produce unexpected results for any negative divisor, but the impacts are most visible for these small negative numbers. The easiest fix might just be to do newVal2.abs().greaterThanOrEquals(val2.abs()) but I haven't fully tested that
This is relevant to Divide, TruncatedDivide, and Modulo.
- Lenguaje dominante
- JavaScript
- Estrellas
- 85
- Forks
- 40
- Merge medio
- 5 d 4 h
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin 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 cqframework/cql-execution
-
Dificultad 4/5 3-5 días Aptitud para principiantes 50/100
cqframework/cql-execution#399 · 3 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
cqframework/cql-execution#398 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
cqframework/cql-execution#397 ·
-
Issue with using type testing operation on FHIR primitivesPosiblemente ocupada @dehall la tomó hace 15 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 54/100
cqframework/cql-execution#391 · 2 comentarios · 1 asignado ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
cqframework/cql-execution#390 · 1 comentario ·
Todos los issues de cqframework/cql-execution
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
obsidianmd/obsidian-help#1169 ·
Los mantenedores suelen responder en 2 días
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish stepPosiblemente ocupada @albertteoh la tomó hoy. Abiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
jaegertracing/jaeger-ui#4739 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
keepassxreboot/keepassxc-browser#3159 · 1 comentario ·
-
Add: ESP 2 RSAbiertoapproved check:passed feeds:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 67/100