I am having a problem with the conversion of singles to doubles in Python.
In my program, I receive float values from a C program passed in an array as single precision. When they are converted to a python value, the lower part of numerical conversion is random memory junk. Is there a way to pre-initialize a conversion, such that the minor precision parts are set to zero?
This value mimics the conversion behavior I am seeing:
In [1]: import ctypes
In [2]: in_float = ctypes.c_float(1.2)
In [3]: in_float
Out[3]: c_float(1.2000000476837158)
In [4]: my_val = in_float.value
In [5]: my_val
Out[5]: 1.2000000476837158
I would like it to set the precision values (smaller than the 8th decimal place) to zero, for all converted values. Is there a way to initialize the values so that the missing converted precision is zero? As an example, I am looking for something like this:
In [4]: my_val = zero_double(in_float.value)
In [5]: my_val
Out[5]: 1.2000000000000000
What I'm looking for is some function (call it zero_double()
for this example) which will give me a conversion assuming that the missing precision values were 0