Pointers are not common in Python, neither the var declaration type. I’m triyng to do this in Python.
C++:
...a function
flt32 f;
int32 sign, exp, man, *tms;
tms = (int *) &f;
...(operations)
*tms = sign | exp | man;
return (f);
as you can see, tms points to f data, but just the int part of the float (btw, this function works perfectly).
With ctypes I can use pointers in Python:
from ctypes import *
f = c_float(12.3)
tms = pointer(f) # tms should be: tms = c_int32(value)
print tms.contents.value #12.3000001907
The problem here is that tms becomes instantly the type of f, so both variables are float (tms should be tms = c_int32(a_value)).
It is possible to use a pointer that just matches the int value from a float variable in Python?
If you really want to do this in Python, you can use ctypes.cast() to cast a float pointer to int pointer, or you can use struct to pack the float value in to a string and unpack it to int. Here is an example:
I use ctypes.cast() to view float value memory as int, and use struct to convert it back: