Single precision float/real and blobs
- iain
- Posts:33
- Joined: Fri May 19, 2017 7:08 pm
Single precision float/real and blobs
Is there any support in scripting for extracting a single precision (4-byte) value from a blob? I can do float/double, but I don't believe there's a native single-precision datatype, so I'm not sure I have a way to use a 4-byte float.
- kilianvp
- Posts:443
- Joined: Fri Jan 16, 2015 10:29 am
Re: Single precision float/real and blobs
Its native but gets saved as a double
From Help: ( qthelp://wincc_oa/doc/Control_Grundlagen/Control_Grundlagen-04.htm )
From Help: ( qthelp://wincc_oa/doc/Control_Grundlagen/Control_Grundlagen-04.htm )
The norm IEEE 754 comprises representations for binary floating point numbers in computers. Furthermore, the norm defines methods for mathematical operations such as roundings. For binary floating point numbers there are two formats available: 32 bit (single precision) and 64 bit (double precision).
WinCC OA provides the C++ data types float and double in CTRL as float and double. Internally these types are mapped to a float variable. The actual value of a float variable is, however, saved as a double. Thus, it provides double precision for floating point numbers.
- iain
- Posts:33
- Joined: Fri May 19, 2017 7:08 pm
Re: Single precision float/real and blobs
I read that, but unfortunately it doesn't answer my question. I have a single-precision float stored in a binary block of data in a blob, and I need to extract it. If I do that with a blobGetValue, and &value is a float which is the same as a double, presumably it will attempt to convert a double-precision value. If I give it a length of 4, will it magically use single-precision arithmetic?
I understand (and prefer) that the value will be stored internally as double-precision, but that isn't what it is in the blob.
I understand (and prefer) that the value will be stored internally as double-precision, but that isn't what it is in the blob.
- iain
- Posts:33
- Joined: Fri May 19, 2017 7:08 pm
Re: Single precision float/real and blobs
Actually, I think I answered my own question. I dumped the bit pattern of a single precision value in C and pasted it into the blobGetValue() example in the docs (tweaking data types, length, endian etc.) and get the correct value out.