为什么LabView将小数转换为微小的浮点数?

时间:2023-02-12 11:34:23

UPDATE: It turns out it was just LabView messing up. Even ints weren't coming through properly. Deleting and recreating some of the nodes solved the problem.

更新:原来只是LabView搞砸了。即使是整数也没有正确地通过。删除并重新创建一些节点解决了这个问题。

I wrote a .Net 3.5 assembly which is being consumed by a LabView engineer. It's at least LabView 7, but I think higher. A method in my assembly is returning an array of objects where each instance has a property of type decimal (among other things). The LabView engineer is doing nothing particular fancy, and is just dumping the sequence to the front-end of the VI, and each of these decimal properties look like very tiny floating point numbers. The actual decimal might be 740.0, but it gets seen in LabView as a double, with a value like 8.12345E-315. That's off by quite a few orders of magnitude!

我写了一个.Net 3.5程序集,由LabView工程师使用。它至少是LabView 7,但我认为更高。我的程序集中的一个方法是返回一个对象数组,其中每个实例都有一个decimal类型的属性(除其他外)。 LabView工程师没有做任何特别的花哨,只是将序列转储到VI的前端,并且这些十进制属性中的每一个看起来都非常微小的浮点数。实际的十进制数可能是740.0,但它在LabView中显示为double,其值类似于8.12345E-315。这相当于几个数量级!

The string and boolean properties are coming through just fine.

字符串和布尔属性正好通过。

Any idea why this is happening?

知道为什么会这样吗?

EDIT: We tested this using a very simple class with some decimal fields and properties, and it worked perfectly fine in LabView. There's something fishy going on with this one DLL, so we're trying some other tests to see if we can replicate the issue using a different DLL.

编辑:我们使用一个带有一些十进制字段和属性的非常简单的类来测试它,并且它在LabView中完美地运行。这个DLL有一些可疑的东西,所以我们正在尝试其他一些测试,看看我们是否可以使用不同的DLL复制问题。

Here is a screenshot of some endian-changing tests. Swapping the endian type of the properties of our simple test class produced the same values. Swapping the endian type of the decimals from the real class library just produces different tiny floats.

以下是一些更改端序的测试的屏幕截图。交换我们的简单测试类的属性的endian类型产生相同的值。从真实类库中交换小数的endian类型只会产生不同的小浮点数。

http://i.imgur.com/WpZ8bYX.jpg

http://i.imgur.com/WpZ8bYX.jpg

4 个解决方案

#1


3  

A LabVIEW double is a 64-bit float in Big Endian (because of its Mac heritage). Your decimal might be something different. If you want to fix it on the LabVIEW side you can use the following code: 为什么LabView将小数转换为微小的浮点数?

LabVIEW double是Big Endian中的64位浮点数(因为它的Mac传统)。您的小数可能会有所不同。如果要在LabVIEW端修复它,可以使用以下代码:

Perhaps he should need to alter the conversion constants around.

也许他应该改变周围的转换常数。

#2


1  

It smells like a bad cast, LabVIEW believing the decimal is a double or single precision floating point number. You should explicitly convert the decimal to a standard floating point, before passing it to LabVIEW. Note that you'll lose digits of precision. Or, find a numeric type that matches the precision of decimal in LabVIEW and make the proper conversion.

它闻起来像一个糟糕的演员,LabVIEW认为十进制是一个双精度或单精度浮点数。在将小数传递给LabVIEW之前,应该将小数显式转换为标准浮点数。请注意,您将丢失精度数字。或者,在LabVIEW中找到与十进制精度匹配的数字类型并进行正确的转换。

#3


0  

Here's a work-around I could do:

这是我可以做的解决方法:

Make an adapter class that changes the interface to use a well-supported data type like double, and then use this adapter class in LabView instead of the original class.

创建一个更改接口的适配器类,以使用支持良好的数据类型(如double),然后在LabView中使用此适配器类而不是原始类。

#4


0  

Try deleting and recreating the property access nodes. Sometimes LabView gets confused and messes up the data.

尝试删除并重新创建属性访问节点。有时LabView会混淆并弄乱数据。

#1


3  

A LabVIEW double is a 64-bit float in Big Endian (because of its Mac heritage). Your decimal might be something different. If you want to fix it on the LabVIEW side you can use the following code: 为什么LabView将小数转换为微小的浮点数?

LabVIEW double是Big Endian中的64位浮点数(因为它的Mac传统)。您的小数可能会有所不同。如果要在LabVIEW端修复它,可以使用以下代码:

Perhaps he should need to alter the conversion constants around.

也许他应该改变周围的转换常数。

#2


1  

It smells like a bad cast, LabVIEW believing the decimal is a double or single precision floating point number. You should explicitly convert the decimal to a standard floating point, before passing it to LabVIEW. Note that you'll lose digits of precision. Or, find a numeric type that matches the precision of decimal in LabVIEW and make the proper conversion.

它闻起来像一个糟糕的演员,LabVIEW认为十进制是一个双精度或单精度浮点数。在将小数传递给LabVIEW之前,应该将小数显式转换为标准浮点数。请注意,您将丢失精度数字。或者,在LabVIEW中找到与十进制精度匹配的数字类型并进行正确的转换。

#3


0  

Here's a work-around I could do:

这是我可以做的解决方法:

Make an adapter class that changes the interface to use a well-supported data type like double, and then use this adapter class in LabView instead of the original class.

创建一个更改接口的适配器类,以使用支持良好的数据类型(如double),然后在LabView中使用此适配器类而不是原始类。

#4


0  

Try deleting and recreating the property access nodes. Sometimes LabView gets confused and messes up the data.

尝试删除并重新创建属性访问节点。有时LabView会混淆并弄乱数据。