Hi All,
I need to pass data to a thread from the PC and for that I see that we can use the persist.UserData[] array. My problem is that my data is float for example 10.34, and the persist.UserData[] is integer. There is any fast method to do it without using 2 variable positions for each number?
many thanks for your support!!
Using persist.UserData with doubles?
Moderators: TomKerekes, dynomotion
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Using persist.UserData with doubles?
Hi gonzalo,
'doubles' are 64 bits and 'floats' are 32 bits. So storing a double will require 2 persist variables.
You can convert your double to a float and save it into one persist variable. It will still have over 6 digits of precision.
Or you might use "fixed point". Multiply your value by some power of 10 and save as an integer. Then when reading it divide by the power of 10. For example for 10.34 multiply by 10000.0 and save integer 103400. Then when reading 103400/10000.0 = 10.3400
'doubles' are 64 bits and 'floats' are 32 bits. So storing a double will require 2 persist variables.
You can convert your double to a float and save it into one persist variable. It will still have over 6 digits of precision.
Or you might use "fixed point". Multiply your value by some power of 10 and save as an integer. Then when reading it divide by the power of 10. For example for 10.34 multiply by 10000.0 and save integer 103400. Then when reading 103400/10000.0 = 10.3400
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Using persist.UserData with doubles?
Great solution Tom, many thanks!!