Precision of unit change (temperature degC to degF) #2888
Replies: 3 comments 3 replies
-
In your examples, your input is a math.unit(math.fraction(60), "degC").toNumber("degF") |
Beta Was this translation helpful? Give feedback.
-
tks for your very quick answer ! In fact i was expected the math configuration was enought ... I try to test your example, it's work. I obtain the exact result. could you explain the performance difference with evalute ? |
Beta Was this translation helpful? Give feedback.
-
tks again for answer. I cannot optimized because unit will change each time i will use it. And i cannot add unit in the evaluate scopes ... You sould add math.fraction type in unit parameter (only number and bigNumber authorized today). Thanks |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm surprised about different precision when using different method to change unit in mathjs.
1/ the expression to change unit degree celcius to fahrenheit is this one :
(VAL °C × 9/5) + 32 = RESULT °F
so it's possible to obtain exact value.
2/ I configure mathjs like this :
const math: math.MathJsStatic = create(all, { epsilon: 1e-20, number: "Fraction", });
3/ the goal : transform 60°C and get 140°F
1rst test :
math.unit(60, "degC").toNumber("degF")
I get 139.999...
2nd test :
math.unit(60, "degC").toNumeric("degF")
I get 139.999...
3rd test :
math.evaluate("60 degree to fahrenheit")
I get 140 !
does someone explain that ?
why only evaluate give the exact result ?
for information evaluate took 0.030ms, toNumber or toNumeric 0.007ms ...
thanks for answer.
Beta Was this translation helpful? Give feedback.
All reactions