您会使用什么测量单位来存储工程数据?
在我们的应用程序中,我们目前决定将所有工程数据存储在 SI 的数据库中。
我担心我们可能会面临数据库或 .NET 数字类型精度和准确度不够的风险。 我还担心我们可能会看到浮点数学的伪影(尽管这可能本身就是一个问题)。
例如,源数据可能是以 Psi(磅每平方英寸)表示的压力量(并从某些第三方服务读取)。 工程师会选择这种测量单位,因为(对于所表达的数量)这往往会给出易于理解、人类可读的数字,而不需要科学记数法。
当我们“标准化”数字时,即当我们将这个数量转换为我们自己的持久性时,我们可能会将其转换为 Pa(帕斯卡),这将需要将该数字乘以或除以其他可能较大的数字。
我们经常最终存储非常大或非常小的数字,更糟糕的是 - 我们可能会对这些数字进行进一步的计算。
目前我们使用ORACLE float和System.Double。
人们对此有何看法?
更新
进一步的研究发现即将推出的 F# 语言(在我撰写的 CTP 中)支持测量单位。
看来我们将能够让 F# 理解用户输入,例如:
9.81<n/s^2> // an acceleration
我们还将能够创建我们自己的派生单位和单位系统。
(来源:msdn.com)
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.
(source: msdn.com)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
牢记有效数字——测量的准确性。 如果PSI只知道整数磅,那么换算成Pa后还有15位小数,仍然只有一位有效数字。
精度与精度不同,对工程单位执行浮点运算需要在运算过程中考虑到这一点 - 不要存储比测量精度更高的精度,不要在计算中使用比已知更高的精度。
编辑:
您还可以考虑使用 NUMERIC(p,s) ,其中可以明确指定精度(位数)和小数位数(小数点右侧的位数)。
如果这不是一个选择,请考虑保留特定测量的精度,以便可以报告和/或在计算中使用它。
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.
我认为只要您能够存储与实际一样多的精度,就没有理由担心。
使用您提供的将 PSI 转换为帕斯卡的示例(1 PSI = 6 894.75 pa),如果我测量 14.7 PSI 并将其转换为帕斯卡,我会得到 101,352.825。 这精度太高了 您需要将其存储为 101,000 以反映测量的真实精度,而不是计算。
请记住,您用于进行转换的任何数字都需要至少与您的测量结果一样精确,这样您在转换过程中就不会失去精度。 转换系数中的精度最好比测量值中的精度位数(至少多一位)。
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.
我认为工程数据通常不够精确,无需担心差异。 你知道工程师的说法“用千分尺测量,用粉笔标记,用斧头切割”。 这大约总结了这一点。 在现实世界中构建的某些东西的计算中,担心 8 个有效数字或 12 个有效数字之间的差异到 2 个有效数字的容差是没有意义的。
I think engineering data usually isn't precise enough to worry about the difference. You know the engineer's expression "measure with a micrometer, mark it with chalk, cut with an axe". That about sums it up. Worrying about the difference between 8 significant figures or 12 in a calculation on something that is built in the real world to 2 significant figures tolerance just doesn't make sense.
为了避免因单位转换而导致精度损失,您可以将测量所得的所有数据存储在测量单位中。当然,这意味着您最终可能会将一些压力值存储在 Pa 中,其他压力值存储在 Psi 中,甚至毫米汞柱。 您必须自己决定这是否会带来比解决的问题更多的问题。
我同意其他答案:在大多数情况下,Oracle 浮点提供的精度远远高于测量本身的精度。
To avoid loss of precision due to unit conversion, you can store all data that comes from measurement in the unit that it was measured in. Of course that means that you may end up with some pressure values being stored in Pa, others in Psi, or even mmHg. You have to decide yourself if that introduces more problems than it solves.
And I agree with the other answers: In most cases, the precision offered by an Oracle float is far higher than the precision of the measurement itself.
嗯,这取决于您想要的精确程度。 请记住,在谈论工程时,仅存储数字 3.20 是不够的,因为在工程方面,3.2 与 3.20 不同。 3.20 意味着比 3.2 更高的精度,可能是 3.15 <= x < 3.25。
Well, it depends on how exact you want to be. Remember than when talking about engineering, it isn't enough to just store the number 3.20, because 3.2 isn't the same as 3.20 when it comes to engineering. 3.20 implies higher accuracy than 3.2, which could be 3.15 <= x < 3.25.