Tag data type change based on return of IF

I'm trying to change a expression tag's data type based on the return of an IF statement.

Right now, the tag is a float and needs to be unless a denominator in the expression is 0.

For example,
IF(tag1=0, "Infinity", tag2/tag1)

The problem I have is that "Infinity" is a string, but I need my tag to be a float data type unless tag1=0.

Is there way to bind the tag's data type to the value of tag1? Do I need a UDT to do this?

Thanks.

How about if({tag1}=0, toFloat("infinity"), {tag2}/{tag1})?

Changing the data type seems like the wrong solution to the problem, but float/doubles have special sentinel values for +/- infinity.

2 Likes

It is also not a solution because a tag's data type is set by a property, not by the expression result.

Thank you for the advice. I modified the expression to include the toFloat function, and no errors. I don't know what sentinel values are, but the "string" seems to be accepted by the expression given the float data type.

Float tags represent their values with IEEE-754 32-bit floats.

By definition, IEEE-754 float has special placeholder values for positive infinity, negative infinity, and NaN: 0x7f800000, 0xff800000, and 0x7fc00000 respectively.

The expression language doesn't have constant operators or the ability to import them, but it does have a toFloat function that attempts a coercion routine from any arbitrary type to floating point. And that coercion routine has special handling for the string value infinity, so that the proper IEEE-754 'sentinel' value is returned.

2 Likes