01-21-2007, 01:10 PM
It works with arrays, too:
dim f as single = 12.3423
dim array(0) as integer = { *cast(integer ptr, @f) }
print *cast(single ptr, @array(0)) ' prints 12.3423
The reinterpretation of the raw data is what you want. It seems a direct cast from single to integer converts the value - that is, it truncates the decimal; C and C++ do the same thing. Casting the pointer type - the address of the data - from float pointer to integer pointer does not convert the value, it just reinterprets the floating point raw data as something else - the value does not change.
dim f as single = 12.3423
dim array(0) as integer = { *cast(integer ptr, @f) }
print *cast(single ptr, @array(0)) ' prints 12.3423
The reinterpretation of the raw data is what you want. It seems a direct cast from single to integer converts the value - that is, it truncates the decimal; C and C++ do the same thing. Casting the pointer type - the address of the data - from float pointer to integer pointer does not convert the value, it just reinterprets the floating point raw data as something else - the value does not change.
stylin: