In Python, how can I translate * (1+ (int *) & x)?

This question is a continuation of this . The Sun Mathematical Library (in C) expression

*(1+(int*)&x)

used to extract the top word of a floating point number x. Here, the OS is assumed to be 64-bit, with a little-endian representation.

I think how to translate the C expression above in Python? The difficulty here is how to translate "&" and "*" into an expression. Btw, maybe Python has a built-in function that extracts the high word of a floating point number?

+4
source share
1 answer

struct:

high_word = struct.pack('<d', x)[4:8]
return struct.unpack('<i', high_word)[0]

high_word - bytes ( str 2.x), x ( IEEE 64- ), 32- ( , [0]).

little-endian , , . , < = ( > !, endian). 64- 32- ints, C . , , .

, ctypes, Python float C - . struct .

+7

All Articles