Arithmetic operations on Quantities with special units should return null

Open
#399 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
50/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript
Domain
backend

Research direction

Start by locating the implementations of Add, Divide, Modulo, Multiply, Subtract, and Truncated Divide, then read how the project represents and validates UCUM units. Add or find tests for arithmetic involving offset and logarithmic special units, including the Fahrenheit/Celsius examples in the issue. Done means these operations return null for invalid or special units instead of producing meaningless quantities or throwing errors.

Written by the indexing model from the issue text.

Description

In the definitions of the following arithmetic operators, the spec says "Attempting to operate on quantities with invalid or special units will result in a null. "

The term "special units" isn't defined in CQL itself so I believe it refers to the UCUM "special units" https://ucum.org/ucum#section-Special-Units-on-non-ratio-Scales which includes things like temperature scales with offsets, and logarithmic scales like pH, dB, etc.

Currently, we don't do anything different for "special" units in these operations, so we can get meaningless results:

define "SpecialUnitsTest": 10 '[degF]' + 2 'Cel'

-->

45.6 '[degF]'

or throw errors:

define "SpecialUnitsTest": 10 '[degF]' * 2 'Cel'

(throws when trying to construct a Quantity with units [degF]2)

Dominant language
JavaScript
Stars
86
Forks
40
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/cql-execution

All issues in cqframework/cql-execution

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.