Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on October 02, 2025, 02:43:30 PM

Title: Filtering and non real numbers
Post by: Bolt on October 02, 2025, 02:43:30 PM
I have a DmD (v2.11.1) project, and I have some IO-Link RTD modules sending data into my analog structures. With the sensors unhooked, they return #INF00 into the UDT's input field. Once connected, it shows the true value. However, If I filter the values, the filtered value continues to shows #QNAN0. If I manually write a 0 to the filtered value in a data view, it then starts to filter fine. Is there a clean way to write some logic to jump start the sequence? How would I reference #INF00 or #QNAN0 values in a comparison contact or math instruction?
Title: Re: Filtering and non real numbers
Post by: BobO on October 02, 2025, 04:52:43 PM
That's a great question. I don't know that I have a great answer. We probably need to talk about that here and come up with a real solution...because I'm not sure there is one.

A hack would be to cast the float as a DWORD and look for the NAN and INF bit patterns. 0x80000000 is the sign bit. 0x7F800000 (8 bits) is the exponent. When all bits are high it is either NAN or INF. The difference between INF and NAN is in the lower 23 fraction bits...0=INF and !0=NAN.

So...if (R0:D & 0x7F800000) == 0x7F800000 you need to clear R0.
Title: Re: Filtering and non real numbers
Post by: Greg on October 03, 2025, 10:21:41 AM
You might could use the TESTNUM instruction? It tests a number and tells you whether or not it is NAN, INF, zero, subnormal, or normal. Then based on its result, you could zero out R0.
Title: Re: Filtering and non real numbers
Post by: BobO on October 03, 2025, 11:48:11 AM
Man...I'm too old for this. Yes, TESTNUM. I completely forgot we added this.

Edit: Apparently in version 2.8.