Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What units of measure would you store engineering data in?

In our app, we currently live with the legacy of a decision to store all engineering data in our database in SI.

I worry that we may run the risk of not having sufficient precision and accuracy in our database or in .NET numeric types. I am also worried that we may see artifacts of floating-point maths (although that is probably a question all to itself).

For example, the source data may have been a pressure quantity expressed (and read in from some 3rd party service) in Psi (pounds per square inch). The engineers will have chosen this unit of measure because (for the quantity being expressed) this will tend to give easily-digested, human-readable numbers without requiring scientific notation.

When we 'standardise' the number, i.e. when we convert this quantity for our own persistence, we might convert it to Pa (Pascals) which will require either multiplying or dividing the number by some other potentially large number.

We often end up storing very large or very small numbers, and worse - we might do further calculations on these numbers.

At present we use ORACLE float and System.Double.

What do people think of this?

UPDATE

Further research has unearthed Units of Measure support in the forthcoming F# language (in CTP as I write).

It seems we'll be able to have F# understand user input such as:

9.81<n/s^2> // an acceleration

We'll also be able to create our own derived units and unit systems.

creating a derived unit for Newtons in F#
(source: msdn.com)

like image 914
rohancragg Avatar asked Dec 17 '22 09:12

rohancragg


2 Answers

Keep significant figures in mind -- the accuracy of the measurement. If the PSI is known to only whole pounds, then after conversion to Pa there are 15 decimals, there is still only one significant figure.

Precision is different from accuracy, and performing floating point operations on engineering units need to take this into account during the operations - don't store more precision than the accuracy of the measurement, don't use more precision in a calculation than is known.


Edit:

You might also consider using NUMERIC(p,s) where the precision (number of digits) and scale (number of digits to the right of the decimal) can be explicitly specified.

If that is not an option, consider persisting the accuracy for a particular measurement so that it may be reported and/or used in calculations.

like image 191
Ken Gentle Avatar answered Mar 04 '23 11:03

Ken Gentle


I think as long as you're able to store exactly as much precision as you actually have, you have no reason to worry.

Using the example you gave of converting PSI to pascals (1 PSI = 6 894.75 pa), If I take a measurement of say 14.7 PSI and convert it to pascals I get 101,352.825. That's too much precision. You'd need to store that as 101,000 to reflect the real precision of the measurement, not the calculation.

Keep in mind that any numbers you use to do conversion need to be at least as precise as your measurements so you don't lose precision during conversion. It's best to have more digits of precision (at least one more) in your conversion factors than in your measurements.

like image 44
Bill the Lizard Avatar answered Mar 04 '23 09:03

Bill the Lizard