04-05-2023 04:29 AM
Hi everyone,
I'm developing a function that can convert any numeric type value to any other numeric type.
Before converting, I would like to check if the output type is big enough to contain the input type.
There is one particular case that bothers me: from U64/I64 to Extended Float (also by extension, Extended Complex).
If the extended float has 128 bits (or actually 80 bits) of precision, it is enough to take an U64 or I64.
If however it has only 64 bits, then it is not enough. How do I know the actual size of an extended float ?
Here it says the extended float size varies depending on the platform without saying much more:
https://www.ni.com/docs/en-US/bundle/labview/page/lvhowto/floating_point_numbers.html
Is there a simple way of knowing the size of an extended float on the current target ?
(appart from measuring the flattened string size of course…)
Thanks,
Raphaël.
04-05-2023 06:43 AM
04-05-2023 08:36 AM
I don't know how you plan for your conversion to work exactly, but one thing you can probably do is maintain a lookup table (probably a map) which has the combination of input and output type as the key. When you first encounter a combo, do a conversion for some max value of that type, then convert back and compare to the original. If the result is the same, that should mean the conversion can work and you can cache that answer.