Christian Lawson-Perfect, Newcastle University
Numbas has been used mainly for pure maths.
Every now and then, someone would ask to mark a quantity with units, and I'd be like
🤷
and then
“It's on my to-do list”
Recently, Nick Walker asked for units, which are very important in chemistry.
NOT bothered about algebraic expressions involving units
88 cm^2/J*s
.GNU units knows just about everything ever.
But there's no JavaScript implementation.
Either
write code to parse its source file myself,
or
find a less-perfect option.
js-quantities does a decent job:
From there, it was very easy:
quantity
data type to JME.Both js-quantities and Numbas use JS' built-in floating point numbers: only ~15 d.p. of accuracy.
Trouble with numbers like Avogadro's constant: \(6.02214086 \times 10^{23} \textrm{mol}^{-1}\).
Using more precise numbers would involve modifying js-quantities.
Now on my to-do list! ✔️
Very easy to use:
width = quantity(random(20..50#5), "cm")
length = quantity(random(50..250#10),"cm") as random("m","cm")
height = quantity(random(10..scalar(width as "cm")#10),"cm")
volume = width*length*height as "m^3"