Unit conversion can turn nonzero values into zero, result in divide-by-zero errors
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- backend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 84
- Fork
- 41
- Merge medio
- 5g 4h
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cqframework/cql-execution
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
cqframework/cql-execution#399 · 3 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
cqframework/cql-execution#398 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
cqframework/cql-execution#397 ·
-
Issue with using type testing operation on FHIR primitivesForse già presa @dehall l’ha presa 15 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 54/100
cqframework/cql-execution#391 · 2 commenti · 1 assegnatario ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
cqframework/cql-execution#390 · 1 commento ·
Tutte le issue di cqframework/cql-execution
Issue simili
-
🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
LibreChat-AI/LibreChat#17887 ·
I maintainer di solito rispondono entro 1 giorno
-
Step-by-step Ash GuideAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
liveshowy/webauthn_components#118 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
showdownjs/showdown#1113 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
dependents/node-precinct#167 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
volumio/volumio-plugins-sources-bookworm#279 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno