Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"300 degC" wrongly converted to "300 K" #926

Closed
jkotan opened this issue Dec 1, 2023 · 4 comments · Fixed by #986
Closed

"300 degC" wrongly converted to "300 K" #926

jkotan opened this issue Dec 1, 2023 · 4 comments · Fixed by #986

Comments

@jkotan
Copy link
Contributor

jkotan commented Dec 1, 2023

Summary

"300 degC" is wrongly converted to "300 K". Probably it is a bug in mathjs. I tested with (10.2.4).

Steps to Reproduce

to reproduce it one can store a scalar value with 'degC' unit or simpler in nodejs

 unit("300 degC").toSI().toJSON()


### Current Behaviour

```json
{ mathjs: 'Unit', value: 300, unit: 'K', fixPrefix: true }

Expected Behaviour

{ mathjs: 'Unit', value: 573.15, unit: 'K', fixPrefix: true }

Extra Details

Workaround for the problem could be to change the above line of the code in convertToSI to something like

 unit(inputValue, inputUnit).to(unit(inputUnit).toSI()).toJSON()

which gives the correct result

{ mathjs: 'Unit', value: 573.15, unit: 'K', fixPrefix: true }
jkotan added a commit to jkotan/scicat-backend-next that referenced this issue Dec 1, 2023
@jkotan
Copy link
Contributor Author

jkotan commented Dec 1, 2023

I've added the patch to #925

@bpedersen2
Copy link
Contributor

Related to josdejong/mathjs#2499 ( and a mathjs upgrade on our side?)

@jkotan
Copy link
Contributor Author

jkotan commented Dec 4, 2023

Hi @bpedersen2,

In the mathjs 12.1.0 still exists so it looks like the problem was not fixed by josdejong/mathjs#2499

(mynodeenv) (myenv) jkotan@xpsjk:~/nest2$ nodejs 
Welcome to Node.js v21.3.0.
Type ".help" for more information.
>  const { unit, version } = await import("mathjs");
undefined
> version
'12.1.0'
>  unit("300 degC").toSI().toJSON()
{ mathjs: 'Unit', value: 300, unit: 'K', fixPrefix: true }
>  unit(300, "degC").to(unit("degC").toSI()).toJSON()
{ mathjs: 'Unit', value: 573.15, unit: 'K', fixPrefix: true }

@nitrosx
Copy link
Contributor

nitrosx commented Jan 2, 2024

@jkotan given that the discussion regarding arrays in Scientific Metadata requires more time to be resolved, could you please isolate the code to solve the problem highlighted in this issue in a separate PR?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants